Properties in parent definition are prohibited in the intellij maven on my mac osx

Viewed 25213

I have a question about my maven configuration on my MAC Intellij. I get an error that ${a-web.version} "properties in parent definition are prohibited" within parent tag in child POM.xml and that properties is defined in parent POM.xml. But this same configuration works well on my Windows Intellij.

Below is my parent POM.xml.

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>***</groupId>
   <artifactId>a-web</artifactId>
   <packaging>pom</packaging>
   <version>${a-web.version}</version>
   <name>a-web project</name>
   <url>http://***</url>

   <properties>
       <a-web.version>1.0.0</a-web.version>
   </properties>

   <modules>
       <module>a-core</module>
       <module>a-web</module>
   </modules>
</project>

And this is my child POM.xml that configure a parent block.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>a-web</artifactId>
        <groupId>***</groupId>
        <version>${a-web.version}</version>
        <relativePath>../</relativePath>
    </parent>

    <artifactId>aweb-web</artifactId>
    <version>${a-web.version}</version>
    <packaging>war</packaging>
    <name>aweb-web</name>
</project>

I've tried many methods from stackoverflow, but no one can fix it. I want to know why this Maven config have different behaviour in Mac and windows and how to fix it.

6 Answers

I have run into a very similar situation when the project started using parent version properties in the commit I have just pulled. The project would not build and felt "ill-imported". An attempt to show effective pom failed with no details presented by IDEA.

As @khmarbaise pointed out in the comments[1], there are some restrictions for properties usage in maven <parent> declarations - the most notable is maven 3.5+ is required. The IDEA might not be using maven new enough (the bundled one in the latest IDEA I have installed was too old) so I had to switch to local install using Settings > Build, Execution, Deployment > Build Tools > Maven > Maven Home Directory. Once pointed to newer version, it did not start to work immediately - some of the restart/rebuild/reimport routines caused the new setting to be effective and the project to successfully import and build again.

Despite the maven version requirement was enforced in pom, it have not caused IDEA to complain the maven version it uses is old. The lack of any details that IDEA fails to inspect the project with the maven it uses did not helped either. Now when everything else works, it still says "Properties in parent definition are prohibited" in pom files.

[1] https://maven.apache.org/maven-ci-friendly.html

Setting property revision in parent pom.xml and then inherit it into children, fixed the issue for me.

<groupId>com.java</groupId>
<artifactId>test</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>

<name>Test</name>
<description>Demo project for Spring Boot</description>

<modules>
    <module>backend</module>
    <module>frontend</module>
</modules>

<properties>
    <revision>1.0.0-SNAPSHOT</revision>
</properties>

In the child's pom.xml:

<parent>
    <artifactId>com.java</artifactId>
    <groupId>test</groupId>
    <version>${revision}</version>
</parent>

<artifactId>backend</artifactId>

I use Maven 3.6.1

Work for me in Idea 18.2:

1) Don't use embeded Maven. Install Maven from official site! It's help me (^_^)

2) You can try to add groupId in child pom, put <groupId>com.iqiyi.lego.web</groupId> before line <artifactId>legoweb-web</artifactId>.

Try this code:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>lego-web</artifactId>
        <groupId>com.iqiyi.lego.web</groupId>
        <version>${lego-web.version}</version>
        <relativePath>../</relativePath>
    </parent>

    **<groupId>com.iqiyi.lego.web</groupId>**
    <artifactId>legoweb-web</artifactId>
    <version>${lego-web.version}</version>
    <packaging>war</packaging>
    <name>legoweb-web</name>
</project>

because your maven version is lower than 3.5.2, try to use version that >=3.5.2,when the ide intellij idea bundled maven version is lower than 3.5.2,try to download zip set to use your own maven instead of the bundled one.

by the way,although maven lower than 3.5.2 show error in intellij idea,but it works ok,you can "mvn package" success.

I think it's because when you push the compiled jar to central maven or private maven such as nexus, you can find the version in META-INF/maven/xxxxx/pom.xml of sub project is

<version>${lego-web.version}</version>

not real value <version>1.0.0</version>.so when you want to release a single jar, you cannot get the true version

It is the IntelliJ IDEA bug.

At least in the IntelliJ IDEA 2019.2 (Ultimate Edition) Build #IU-192.5728.98, built on July 23, 2019

Related