The error "Properties in parent definition are prohibited" occurs because Maven does not allow property substitution (e.g., ${...}
) in the <version>
tag of the <parent>
section. To work around this limitation, you can use Maven profiles, or avoid directly using properties in the <parent>
section.
Here are possible solutions:
Solution 1: Directly Define the Parent Version
If you must define the parent version dynamically, the only way is to avoid properties in the <parent>
tag and set the version explicitly:
xml
Copy code
<parent> <groupId>com.igen</groupId> <artifactId>igen-sdl-parent</artifactId> <version>1.0.10-XY-SNAPSHOT</version> </parent>
Solution 2: Use Profiles in the Child POM
If you need to switch parent versions based on an environment (e.g., dev or prod), define Maven profiles with explicit versions and activate them at build time.
-
Add profiles to the child POM:
<profiles> <profile> <id>dev</id> <properties> <parent.version>1.0.10-XY-SNAPSHOT</parent.version> </properties> </profile> <profile> <id>prod</id> <properties> <parent.version>1.0.11-XY-SNAPSHOT</parent.version> </properties> </profile> </profiles>
-
Use the version in the
<parent>
tag:<parent> <groupId>com.igen</groupId> <artifactId>igen-sdl-parent</artifactId> <version>${parent.version}</version> </parent>
-
Build with the appropriate profile:
mvn clean install -Pdev
or
mvn clean install -Pprod
Solution 3: Use Command-Line Arguments
You can pass the parent version as a command-line argument during the build process.
-
Define the
<parent>
section with a placeholder:<parent> <groupId>com.igen</groupId> <artifactId>igen-sdl-parent</artifactId> <version>${parent.version}</version> </parent>
-
Run Maven with the
-Dparent.version
argument to specify the version dynamically:mvn clean install -Dparent.version=1.0.11-XY-SNAPSHOT
Solution 4: Use a Parent Locator Script
Another approach is to create a script that dynamically modifies the POM before invoking Maven.
- Write a script to replace
${parent.version}
in your POM file with the desired version. - Run the script before executing Maven.
For example, using sed
in Linux/Mac:
sed -i 's/${parent.version}/1.0.11-XY-SNAPSHOT/' pom.xml mvn clean install
Best Practice Recommendation
- If the parent version changes infrequently and across multiple projects, consider maintaining multiple POMs for different environments.
- Use profiles if you need dynamic switching between parent versions for multiple environments.
- Avoid using properties directly in the
<parent>
tag unless required to reduce complexity.