inherit profile based property in maven pom.xml - maven

I have parent maven pom.xml like this:
<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>mygroup</groupId>
<artifactId>mygroup-sharing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<profiles>
<profile>
<id>linux-i386</id>
<activation>
<os>
<family>linux</family>
<arch>x86</arch>
</os>
<property>
<name>platform.suffix</name>
<value>linux-i386</value>
</property>
</activation>
</profile>
<profile>
<id>solaris-i386</id>
<activation>
<os>
<family>solaris</family>
<arch>x86</arch>
</os>
<property>
<name>platform.suffix</name>
<value>solaris-i386</value>
</property>
</activation>
</profile>
...
</profiles>
<properties>
<depr.version>3.6.1-${platform.suffix}</depr.version>
</properties>
</project>
and I have child (and I will have more) pom in subdirectory:
<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>
<artifactId>mygroup-submodule</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>mygroup</groupId>
<artifactId>mygroup-sharing</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
...
<dependencies>
...
<dependency>
<groupId>mygroup</groupId>
<artifactId>depr</artifactId>
<version>${depr.version}</version>
</dependency>
...
</dependencies>
</project>
The problem is, that the version is badly used when trying to compile the child project:
Downloading: http://myserver/nexus/content/groups/public//mygroup/depr/3.6.1-${platform.suffix}/depr-3.6.1-${platform.suffix}.pom
...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) mygroup:depr:jar:3.6.1-${platform.suffix}
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=mygroup -DartifactId=depr -Dversion=3.6.1-${platform.suffix} -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=mygroup -DartifactId=depr -Dversion=3.6.1-${platform.suffix} -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) mygroup:mygroup-submodule:jar:1.0-SNAPSHOT
2) mygroup:depr:jar:3.6.1-${platform.suffix}
----------
....
... so as you can see, the property platform.suffix is badly applied when using the parent pom.
Also there's warning when running mvn -X install
[WARNING] Overriding profile: 'linux-i386' (source: pom) with new instance from source: pom
but there's no definition of profiles in the child pom file.
If I use this in each pom.xml file, it works properly. But I don't want to have copy-pasted this long part of pom.xml as it also can be extended (with more platforms).
Is there any other way how to share this type (platform suffix) configuration across other modules ?

Related

Compile project that references installed project

I have a library module that I created through Maven, there is pom.xml what get dependencies:
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.18.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.library</groupId>
<artifactId>commons</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>commons</name>
<description>common dependencies library</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
With the above pom, I successfully installed it into the local maven repository by using mvn install.
In another project my-service, which uses this installed library, within the IntelliJ IDEA, it is fine compiling and running. There is the pom.xml for the my-service
<?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>com.example</groupId>
<artifactId>my-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-service</name>
<description>My Services</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.18.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- other dependencies ... -->
<dependency>
<groupId>com.example.library</groupId>
<artifactId>commons</artifactId>
<version>1.0.0</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
However, when running with mvn compile, I got the following errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-service: Compilation failure: Compilation failure:
[ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[3,45] package com.example.library.commons.filters does not exist
[ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[17,13] cannot find symbol
[ERROR] symbol: class SessionFilter
[ERROR] location: class com.example.myservice.configs.WebSecurityConfig
[ERROR] /Users/doe/IdeaProjects/my-service/src/main/java/com/example/myservice/configs/WebSecurityConfig.java:[19,36] cannot find symbol
[ERROR] symbol: class SessionFilter
[ERROR] location: class com.example.myservice.configs.WebSecurityConfig
The library project is created as part of the IntelliJ IDEA module within the same project as the my-service module. I guess the IntelliJ IDEA knows how to internally references module to compile the depending modules, but with Maven, it is a different story.
My goal is to compile and package the my-service module as a single jar that includes the commons library module. Now I can't even get it to compile with Maven, what did I do wrong?
Apache Maven version 3.3.9 . Operating system: OS X.
It turns out the Spring-boot-maven plugin is not needed in the library project because a library doesn't need to produce an executable ueber jar. After removing the plugin, it compiles successfully.

Maven run only the parent pom with a profile

In my project, I have a custom profile custom-profile-name.
A simplified structure of my POM looks like this:
<artifactId>parent</artifactId>
<modules>
<module>child</module>
</modules>
When I run
mvn help:active-profiles -P custom-profile-name
I get:
Active Profiles for Project 'org.sample:parent:pom':
The following profiles are active:
custom-profile-name
Active Profiles for Project 'org.sample:child':
The following profiles are active:
custom-profile-name
I've been reading about profile inheritance and If I understand correctly, profiles should not be inherited. Can anyone explain why the custom-profile-name is active in the child module.
My ultimate goal is to execute the parent with one configuration of a custom plugin and all child modules with another configuration of the same plugin.
Not sure why both parent and child modules are getting activated for custom-profile-name. But to get whats needed for you can be done by defining properties inside the profile.
Example:
<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.mycompany.app</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>parent-app</name>
<url>http://maven.apache.org</url>
<modules>
<module>child</module>
</modules>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>child</module>
</modules>
<properties>
<parentProp>foo</parentProp>
<childProp>foo</childProp>
</properties>
</profile>
<profile>
<id>custom-profile-name</id>
<modules>
<module>child</module>
</modules>
<properties>
<parentProp>xyz</parentProp>
<childProp>abc</childProp>
</properties>
</profile>
</profiles>
The 'parentProp' is a configuration used by the parent pom and 'childProp' is the configuration used by the child pom. From the configuration it can be seen that the default profile and the 'custom-profile-name' profile behaves differently as the values for the properties is different.

Maven Packing Type Based on Profile

I am using a found example on stackoverflow that dynamically changes the packaging type based on profile
Changing packaging based on active profile in pom
This is a snippet of my pom.xml
<?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.scene7.is.qa</groupId>
<artifactId>jorogumo</artifactId>
<packaging>${packaging.type}</packaging>
...
<profile>
<id>JorogumoReportingWebApp</id>
<properties>
<packaging.type>war</packaging.type>
<final.name>jorogumo</final.name>
</properties>
...
Based on the upvotes from the answer link above I am assuming this should work, but I receive an error when cleaning
$ mvn clean
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.scene7.is.qa:jorogumo:0.0.1-SNAPSHOT (/Users/xyz/working/_workspaces/Scene7/java/jorogumo/pom.xml) has 1 error
[ERROR] Unknown packaging: ${packaging.type} # line 10, column 13
Am I missing something? Or is this the wrong approach?
My end goal is to share common java classes between the web app and the command line jar.
I ended up creating a default packing.type property with a value:
<modelVersion>4.0.0</modelVersion>
<groupId>com.scene7.is.qa</groupId>
<artifactId>jorogumo</artifactId>
<packaging>${packaging.type}</packaging>
...
<properties>
<packaging.type>war</packaging.type>
</properties>
<profiles>
<profile>
<id>JorogumoReportingWebApp</id>
<properties>
<packaging.type>war</packaging.type>
<final.name>jorogumo</final.name>
</properties>
...

How to build a multi-module maven project in jenkins

I have a projects structure as follows:
ProjectParent
- pom.xml
ProjectApp
-pom.xml
ProjectAPI
-pom.xml
ProjectModels
-pom.xml
ProjectServices
-pom.xml
Etc..
ProjectModels/ProjectsServices are dependencies within ProjectAPI/ProjectApp.
Should I create separate jobs within Jenkins to build each module separately?
I created a job for ProjectAPP but get the following error below (Have set goals and actions to "clean install":
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject-app 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT is missing,
no dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-entities/0.0.1-SNAPSHOT/myproject-entities-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT is missing, no
dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-services/0.0.1-SNAPSHOT/myproject-services-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-services:jar:0.0.1-SNAPSHOT is missing, no
dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-persistence/0.0.1-SNAPSHOT/myproject-persistence-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT is missing, no
dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.jar
......
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project myproject-app: Could not resolve dependencies
for project com.myproject:myproject-app:war:0.0.1-SNAPSHOT: The
following artifacts could not be resolved:
com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT,
com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT,
com.myproject:myproject-services:jar:0.0.1-SNAPSHOT,
com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT: Could not find
artifact com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT in
org.springframework.maven.snapshot
(http://maven.springframework.org/snapshot)
ProjectParent 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>myproject-entities</module>
<module>myproject-services</module>
<module>myproject-persistence</module>
<module>myproject-app</module>
<module>myproject-merchant</module>
<module>myproject-common-config</module>
<module>myproject-api</module>
</modules>
<dependencyManagement>
<dependencies>
...
</dependencies>
</dependencyManagement>
<repositories>
...
</repositories>
<build>
...
</build>
<properties>
...
<myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
<myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
<myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
</properties>
</project>
ProjectApp Pom
<?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>com.myproject</groupId>
<artifactId>myproject-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>myproject-app</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>myproject-app</name>
<url>http://maven.apache.org</url>
<dependencies>
...
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-common-config</artifactId>
<version>${myproject-common-config}</version>
</dependency>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-entities</artifactId>
<version>${myproject-entities-version}</version>
</dependency>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-services</artifactId>
<version>${myproject-services-version}</version>
</dependency>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-persistence</artifactId>
<version>${myproject-persistence-version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<myproject-common-config>0.0.1-SNAPSHOT</myproject-common-config>
<myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
<myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
<myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
</properties>
</project>
Am I using the wrong goals? Do I need to chain a number of commands? i.e. build other modules first?
I'm using Maven 3.
NOTE: I changed the target to "clean install" against the ParentProject Pom and everything builds correctly.
Thanks
The problem is that you can't create a project solely for the ProjectApp module because it depends on the other modules below the ProjectApp parent. If you don't deploy those modules to your maven repository, maven is not able to find them in the repository nor in the build reactor.
Instead you should create the job for the parent. This will build the necessary modules.
You may also work with the option also-make-dependants when you have a job for ProjectApp, but I haven't any experience with this.
Had the same problem, and SpaceTrucker answer helped me.
Hence I just run something like:
.../ProjectParent$ mvn -am -pl ProjectApp test

Maven pom and profile usage to generate two different war(part of main module) files with differing profile settings

I have a maven module project that has following modules:
Parent pom
- core
- web-commons
- admin
- web
Both web and admin have dependency on core and web-commons, and each module has its own profile.xml.
Until now, both our admin and web shared the same datasource name and web server, so all the way from core to web-commons we had a reference to this datasource name. (Actually a datasource macro placeholder that gets replaced from profiles.xml during build time).
However, we have to separate the datasources and now I am trying to figure out best way to do this.
Here is the code snippets for clarity.
Parent 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>
<groupId>com.my.groupId</groupId>
<artifactId>parentArtifact</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
...
<modules>
<<module>core</module>
<module>web-commons</module>
<module>admin</module>
<module>web</module>
</modules>
<project>
Core pom.xml
<?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.my.groupId</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
...
<project>
core Profiles.xml
<profilesXml xmlns="http://maven.apache.org/PROFILES/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd">
<profiles>
<profile>
<id>DEV</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<datasource.name>web_datasource</datasource.name>
...
</properties>
</profile>
</profiles>
</profilesXml>
web-commons pom.xml
<?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.my.groupId</groupId>
<artifactId>web-commons</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
...
<dependencies>
<dependency>
<groupId>com.my.groupId</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<project>
web-commons Profiles.xml
<profilesXml xmlns="http://maven.apache.org/PROFILES/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd">
<profiles>
<profile>
<id>DEV</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<datasource.name>web_datasource</datasource.name>
...
</properties>
</profile>
</profiles>
</profilesXml>
web pom.xml
<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>
<artifactId>parentArtifactId</artifactId>
<groupId>com.my.groupId</groupId>
<version>1.0</version>
</parent>
<groupId>com.my.groupId</groupId>
<artifactId>web</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.my.groupId</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.my.groupId</groupId>
<artifactId>web-commons</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
....
</project>
web profiles.xml
<profilesXml xmlns="http://maven.apache.org/PROFILES/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd">
<profiles>
<profile>
<id>DEV</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<timeout>90</timeout>
...
</properties>
</profile>
</profiles>
</profilesXml>
admin pom.xml
<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>
<artifactId>parentArtifactId</artifactId>
<groupId>com.my.groupId</groupId>
<version>1.0</version>
</parent>
<groupId>com.my.groupId</groupId>
<artifactId>admin</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.my.groupId</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.my.groupId</groupId>
<artifactId>web-commons</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
....
</project>
admin profiles.xml
<profilesXml xmlns="http://maven.apache.org/PROFILES/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd">
<profiles>
<profile>
<id>DEV</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<timeout>120</timeout>
...
</properties>
</profile>
</profiles>
</profilesXml>
Possible solutions:
Change the core profiles.xml and all subsequent profiles.xml, and then run the
mvn clean package -PDEV_WEB and then again
mvn clean package -PDEV_ADMIN
core Profiles.xml
<profilesXml xmlns="http://maven.apache.org/PROFILES/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd">
<profiles>
<profile>
<id>DEV_WEB</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<datasource.name>web_datasource</datasource.name>
...
</properties>
</profile>
<profile>
<id>DEV_ADMIN</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<datasource.name>admin_datasource</datasource.name>
...
</properties>
</profile>
</profiles>
</profilesXml>
Keep all the pom.xml and profiles.xml as-is and find a maven lifecycle point where we can generate web.war (that has core.jar and web-commons.jar that has web_datasource) and then generate admin.war (that has core.jar and web-commons.jar that has admin_datasource) Not sure how, but will have to investigate this further.
Separate web and admin deployment and keep the datasource name, but have two different web servers that have different datasource settings. [Least likely option]
I'd suggest you make your artifacts environment-agnostic and make them read their configurations from e. g. system properties and/or config files that live outside the artifacts on the file system.
The kind of profile abundance you suggest seems to be a maintainance nightmare to me. What if you cut a release with the release plugin? Which profile would you activate then? Also, note that support for profile.xml was removed in Maven 3.
I ended up refactoring the code so that core and web commons do not have any direct reference to data source profile. All the data source entries have been removed from profiles.xml in core/web commons and new entries made in relevant modules (web/admin). [I know this is not a ideal solution]
Web now has its own entry for datasource-name in profiles.xml, similarly admin has its own datasource-name entry in profiles.xml. Also, core defined a jndi lookup data source spring bean, this is moved to relevant modules that have dependencies (web/admin).
Web profiles.xml
<profilesXmlmlns="http://maven.apache.org/PROFILES/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd">
<profiles>
<profile>
<id>DEV</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<timeout>90</timeout>
<datasource-name>dev_web</datasource-name>
...
</properties>
</profile>
</profiles>
</profilesXml>
Admin profiles.xml
<profilesXmlmlns="http://maven.apache.org/PROFILES/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd">
<profiles>
<profile>
<id>DEV</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<timeout>120</timeout>
<datasource-name>dev_admin</datasource-name>
...
</properties>
</profile>
</profiles>
</profilesXml>

Resources