i have 2 profiles in my pom.xml and need to package 2 WAR files simultaneously
this is pom
<profiles>
<profile>
<id>TEST</id>
-- scripts
</profile>
<profile>
<id>DEV</id>
-- scripts
</profile>
</profiles>
i tried
clean package -P Dev,Test
but alywas the generated WAR is the last one (Test) and Dev profile not run
You can use multiple P arguments:
mvn clean package -P Dev -P Test
If you want to do that, you need to separate Maven runs.
After a lot of investigation i figure out it can't be done
Related
I am using Maven 3.6.0 and OpenJDK8 on Ubuntu 18.04 (also tested with Alpine Linux).
I have a pom.xml in the root of my project that includes my submodules :
...
<modules>
<module>mysubmodule</module>
</modules>
...
In the mysubmodule folder, the pom.xml has a profile that I want to activate based on a property passed to the mvn executable:
...
<profile>
<id>my-profile</id>
<activation>
<property>
<name>activateMyProfile</name>
</property>
</activation>
...
</profile>
...
I then execute mvn to start the build, but the profile is never activated:
If I run mvn -DactivateMyProfile release:prepare from the root of my project, the profile is never activated and never runs
If I run mvn release:prepare from the root of my project, the profile is never run.
I also tried the inverse:
...
<profile>
<id>my-profile</id>
<activation>
<property>
<name>!doNotActivateMyProfile</name>
</property>
</activation>
...
</profile>
...
If I run mvn -DdoNotActivateMyProfile release:prepare from the root of my project, the profile is still executed
If I run mvn release:prepare from the root of my project, the profile is also executed
It looks like mvn is not able to see the properties being passed through the command line. What is the correct way to activate a profile in a submodule using a property?
As I am using the maven release plugin, parameters must be passed using the -Darguments argument.
For example, instead of using mvn -DactivateMyProfile release:prepare, the correct invocation is: mvn -Darguments=-DactivateMyProfile release:prepare
If there are multiple arguments, use mvn -Darguments="-DactivateMyProfile -DsomeOtherArg -DanotherArg=something" release:prepare
Can we build specific child from a parent Pom in Maven.May be using a file that mentions the name of the modules to be included.
If you in root location of your project you can simply define that on command line of Maven like this:
mvn -pl ModuleYouWouldLikeToBuild package
Excerpt from the command line help:
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
If this module what you like to build is used by an other module you can decide to let maven analyze which one and build that depending module also by using:
mvn -pl Module --also-make-dependents
or short version:
mvn -pl Module -amd
If you have modules which are used by the module you triggered to build you can also add:
mvn -pl Module --also-make
or short version:
mvn -pl Module -am
Assume your root project has 3 modules: module-A, module-B and module-C.
Run the commands below from your root project.
If you want to build module-C, run: mvn clean install –pl module-C
In case module-C depends on module-A, run:
mvn clean install –pl module-C –am to build module-A and module-C
You can use maven profile to achieve this.
<project>
...
<profiles>
<profile>
<id>build1</id>
<activation>
<property>build1</property>
</activation>
<modules>
<module>module1</module>
</modules>
</profile>
<profile>
<id>build2</id>
<activation>
<file>
<exists>test2.file</exists>
</file>
</activation>
<modules>
<module>module2</module>
<module>module3</module>
</modules>
</profile>
</profiles>
</project>
You can activate profile by some conditions, eg. present or missing files, existing properties and so on.
More info about maven profile:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
I have two maven profiles, the only difference is a line. Other than that the two profiles are identical. Is there a way to share the common code blocks in the POM without copy/paste? For example, declare a base profile and inherit it, and change the corresponding line in the children? I do not want to use any environmental variable approach.
<profiles>
<profile>
<id>parent-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<!-- common config -->
</profile>
<profile>
<id>profile-a</id>
<!-- specific config for a -->
</profile>
<profile>
<id>profile-b</id>
<!-- specific config for b -->
</profile>
</profiles>
And just run:
mvn args -P profile-a or mvn args -P profile-b
And if you dont want the parent-profile to be active by default, just delete the specified line and every time you wish to activate one profile, add the parent profile to mvn like:
mvn args -P parent-profile, profile-a or mvn args -P parent-profile, profile-b
We are using maven-exec-plugin during prepare resources phase to create binary file which is later packaged into jar. Exec launches script which reads excel sheet and creates sqlite db.
Now the script is run always, even if I don't run clean. How to configure plugin so it would run only when:
Output file does not exist.
OR Output file exist but last modification date is older then source file.
You may use <profile> activation to run the plugin only when target/afile.log does not exists :
<profiles>
<profile>
<id>run-exec</id>
<activation>
<file>
<missing>target/afile.log</missing>
</file>
</activation>
...
</profile>
</profiles>
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I exclude certain modules from a maven build using the commandline
I am running a maven clean install in a pom file which includes several modules (and sub-modules). I was wondering if it is possible to run a maven build but specifying on command line to skip a module from the build ( at the moment I exclude them manually from the build, but Id prefer to do it via command line).
I know that with -pl you can selectively choose projects, but what I would like is to selectively exclude (in a blacklist fashion) some.
You could have a separate <modules> section in a profile, and activate the profile you need in the command line.
Example:
<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>...</modules> <!-- module set 1 -->
</profile>
<profile>
<id>profile-2</id>
<modules>...</modules> <!-- module set 2 -->
</profile>
</profiles>
Now, dependent on your current need, execute
mvn install
mvn install -P profile-2
Note that you'd have to think it over carefully, there must be no cross-profile dependencies on the excluded module.