Sunday, 29 September 2013

Variable dependency of submodule with property from settings.xml

Variable dependency of submodule with property from settings.xml

I have a sample maven project with the following structure:
parent
frontend
backend
Frontend depends on Backend. Backend has a database driver dependency for
testing. However, this dependency should be dependent on the developers
settings.xml
<dependency>
<groupId>${database.driver.groupId}</groupId>
<artifactId>${database.driver.artifactId}</artifactId>
<version>${database.driver.version}</version>
<scope>test</scope>
</dependency>
In my settings.xml I have this:
<profile>
<id>database</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<database.driver.groupId>mysql</database.driver.groupId>
<database.driver.artifactId>mysql-connector-java</database.driver.artifactId>
<database.driver.version>5.1.9</database.driver.version>
</properties>
</profile>
When I run only the backend the properties are correctly substituted.
However, if I run frontend (or parent) transitive dependencies are not
available for frontend because it can't substitute the properties anymore:
[WARNING] The POM for de.phil.mvntest:business:jar:0.0.1-SNAPSHOT is
invalid, transitive dependencies (if any) will not be available: 2
problems were encountered while building the effective model for
de.phil.mvntest:business:0.0.1-SNAPSHOT
[ERROR] 'dependencies.dependency.artifactId' for
${database.driver.groupId}:${database.driver.artifactId}:jar with value
'${database.driver.artifactId}' does not match a valid id pattern. @
[ERROR] 'dependencies.dependency.groupId' for
${database.driver.groupId}:${database.driver.artifactId}:jar with value
'${database.driver.groupId}' does not match a valid id pattern. @
The funny part is, that if I move the profile declaration into the
parent's pom.xml it works fine!
So my question is, why are the properties of a submodule not substituted
when they come from the settings.xml.
Note: "help:active-profiles -N" shows that the profile from the
settings.xml is active.
Note2: The Maven version came with STS and is Embedded 3.0.4



Following the settins.xml and poms
backend
<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>de.phil.mvntest</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>backend</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${database.driver.groupId}</groupId>
<artifactId>${database.driver.artifactId}</artifactId>
<version>${database.driver.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
fontend
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.phil.mvntest</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>frontend</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>de.phil.mvntest</groupId>
<artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
parent
<?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>
<groupId>de.phil.mvntest</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>backend</module>
<module>frontend</module>
</modules>
</project>
settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
http://maven.apache.org/xsd/settings-1.1.0.xsd">
<profiles>
<profile>
<id>database</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<database.driver>com.mysql.jdbc.Driver</database.driver>
<database.url>jdbc:mysql://localhost:3306/IBS</database.url>
<database.username>root</database.username>
<database.password />
<database.defaultSchemaName>IBS</database.defaultSchemaName>
<database.driver.groupId>mysql</database.driver.groupId>
<database.driver.artifactId>mysql-connector-java</database.driver.artifactId>
<database.driver.version>5.1.9</database.driver.version>
</properties>
</profile>
</profiles>
</settings>

No comments:

Post a Comment