The error “Properties in parent definition are prohibited“ occurs because Maven does not allow

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.

  1. 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>

  2. Use the version in the <parent> tag:

    <parent> <groupId>com.igen</groupId> <artifactId>igen-sdl-parent</artifactId> <version>${parent.version}</version> </parent>

  3. 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.

  1. Define the <parent> section with a placeholder:

    <parent> <groupId>com.igen</groupId> <artifactId>igen-sdl-parent</artifactId> <version>${parent.version}</version> </parent>

  2. 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.

  1. Write a script to replace ${parent.version} in your POM file with the desired version.
  2. 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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值