Tuesday, 15 July 2014

multi module - Maven profiles behaviour with plugins -



multi module - Maven profiles behaviour with plugins -

let's have multi-module maven project. 1 of project's pom file following:

<?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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>some.group</groupid> <artifactid>parent-artifact</artifactid> <version>0.14.0-snapshot</version> <relativepath>../../pom.xml</relativepath> </parent> <artifactid>artifact-x</artifactid> <packaging>jar</packaging> <name>artifact x</name> <dependencies> <dependency> <groupid>some.group</groupid> <artifactid>artifact-a</artifactid> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupid>some.group</groupid> <artifactid>artifact-b</artifactid> <version>${project.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupid>some.group</groupid> <artifactid>artifact-c</artifactid> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupid>some.group</groupid> <artifactid>artifact-d</artifactid> <version>${project.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupid>some.group</groupid> <artifactid>artifact-e</artifactid> <version>${project.version}</version> <scope>runtime</scope> </dependency> </dependencies> </project>

let's reason, want move of dependencies in pom file profile. so, move artifact-c, artifact-d, artifact-e dependencies when using profile-1. profile-1 used in other poms in project. new pom becomes:

<?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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>some.group</groupid> <artifactid>parent-artifact</artifactid> <version>0.14.0-snapshot</version> <relativepath>../../pom.xml</relativepath> </parent> <artifactid>artifact-x</artifactid> <packaging>jar</packaging> <name>artifact x</name> <dependencies> <dependency> <groupid>some.group</groupid> <artifactid>artifact-a</artifactid> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupid>some.group</groupid> <artifactid>artifact-b</artifactid> <version>${project.version}</version> <scope>runtime</scope> </dependency> </dependencies> <profiles> <profile> <id>profile-1</id> <dependencies> <dependency> <groupid>some.group</groupid> <artifactid>artifact-c</artifactid> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupid>some.group</groupid> <artifactid>artifact-d</artifactid> <version>${project.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupid>some.group</groupid> <artifactid>artifact-e</artifactid> <version>${project.version}</version> <scope>runtime</scope> </dependency> </dependencies> </profile> </profiles> </project>

when building, run mvn -pprofile-1 clean package @ top-level pom in both cases. expectation moving dependencies profile shouldn't alter when -pprofile-1 specified. didn't happen - of plugins started behaving erroneously - ex. maven-shade-plugin didn't set artifact-c, artifact-d , artifact-e in shaded jar etc.

am doing wrong? profiles not supposed work this?

are these 2 pom files not equivalent when used -pprofile-1?

even though pom.xml allows define this, shouldn't (call design flaw). of times doesn't create sense add together dependencies in profile. valid constructions dependencies based on os or on jdk version. remember pom.xml acts "consumer-pom", other projects using artifact read pom file transitive dependencies. in such case can't active profile anymore.

in conclusion: don't seek solve profiles. there must improve solution.

maven multi-module

No comments:

Post a Comment