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.
The root cause was that the pom. xml file was ignored (Settings - Build, Execution, Deployment - Maven - Ignored Files). Thus, updates to this file pulling in a new version of a dependency did not trigger anything meaningful in IntelliJ IDEA (causing compilation issues).
In your POM, select the dependency you want to extract. Press Ctrl+Alt+M or select Refactor | Extract | Extract Managed Dependency. IntelliJ IDEA extracts the selected dependency into a parent POM, automatically creating a dependencyManagement section and a full dependency definition.
A parent pom. xml file (or super POM) in Maven is used to structure the project in order to avoid redundancies and duplicate configurations by using an inheritance between different pom. xml files. If any dependency or properties are configured in both - parent and child - pom.
Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. Or they can be used by plugins as default values, for example: In your case you have defined properties as version of java.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With