java - Issue with Maven properties -


i have parent pom below.

<?xml version="1.0" encoding="utf-8"?> <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>com.parent.pom</groupid>     <artifactid>parent-pom</artifactid>     <version>1.0.0</version>     <name>parentpom</name>     <packaging>pom</packaging>     <properties>         <parentversion>1.0.0</parentversion>     </properties> </project> 

and child pom .

<?xml version="1.0" encoding="utf-8"?> <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>     <groupid>com.parent.pom</groupid>     <artifactid>parent-pom</artifactid>     <version>${parentversion}</version>     <relativepath>../pom.xml</relativepath>   </parent>     <groupid>com.child.pom</groupid>     <artifactid>child-pom</artifactid>     <version>2.0.0</version>     <name>childpom</name>     <packaging>pom</packaging> </project> 

my folder structure

pom-test(root folder having parent pom) --- child(having child pom)

when ran mvn clean install in child getting exception below.

error] build not read 1 project -> [help 1] error] error]   project com.child.pom:child-pom:2.0.0 (c:\users\kk\desktop\pom-test\child\pom.xml) has 1 error error]     non-resolvable parent pom: not transfer artifact com.parent.pom:parent-pom:pom:${parentversion} from/to central (http://repo.maven.apache.org/ maven2): illegal character in path @ index 63: http://repo.maven.apache.org/maven2/com/parent/pom/parent-pom/${parentversion}/parent-pom-${parentversion}.pom  , 'parent.relativepath' points @ wrong local pom @ line 5, column 9 -> [help 2 

why not able install pom ?

starting with maven 3.2.1 can use properties ${revision}, ${sha1} , ${changelist} in versions if like.

so can use this:

  <groupid>com.soebes.examples.j2ee</groupid>   <artifactid>parent</artifactid>   <version>${revision}</version>   <packaging>pom</packaging>    <modules>     <module>child</module>   </modules> 

and can use in childs this:

  <modelversion>4.0.0</modelversion>    <parent>     <groupid>com.soebes.examples.j2ee</groupid>     <artifactid>parent</artifactid>     <version>${revision}</version>   </parent>    <artifactid>child</artifactid> 

now have call maven this:

mvn -drevision=1.2.3-snapshot clean package mvn -drevision=1.2.3 clean package 

you can take full example here.. if need change version recommend use versions-maven-plugin change versions within build whatever version (for example in ci solution) or in making releases can use maven-release-plugin handle this. , development should use like: 1.2.3.45-snapshot (emphasize -snapshot) identify being under current development.

furthermore given <relativepath>../pom.xml</relatvepath> not needed cause it's default can omitted.

very important. if have structure described child should have same version parent (in case of multi module build given example) or parent (corporate pom) should separate project means separate git repository. , furthermore other explanation take here: https://stackoverflow.com/a/35057833/296328


Comments