I have two profiles for different environments in pom.xml, I have to run mvn -PTest1 install and mvn -PTest2 install command to get these profiles in use. Can we integrate two separate maven commands in a single one (like mvn clean install)?
Here is my Pom entry
<profiles>
<profile>
<id>Test1</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>sparrow-type</name>
<value>African</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>
com.endeca
</groupId>
<artifactId>
endeca_navigation_Test1
</artifactId>
<version>
6.1
</version>
<!--<version>stable</version> -->
<scope>
compile
</scope>
</dependency>
</profile>
<profile>
<id>Test2</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>sparrow-type</name>
<value>African</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>
com.endeca
</groupId>
<artifactId>
endeca_navigation_Test2
</artifactId>
<version>
6.1
</version>
<!--<version>stable</version> -->
<scope>
compile
</scope>
</dependency>
</dependencies>
</profile>
</profiles>
It will helpfull to manage hudson job using single command
Based on the documentation and discussion here, try separating profile names with a comma:
mvn install -P Test1,Test2
Mifeet's answer is correct, but in Windows PowerShell you should quote parameters, otherwise you'll get "unknown lifecycle phase" error.
mvn install -P 'Test1,Test2'
For me Mifeet's answer isn't working. I get "unknown lifecycle phase Test2". For me this is working:
mvn install -PTest1 -PTest2
Based on the maven help command
-P,--activate-profiles <arg> Comma-delimited list of profiles to activate
So you can run mvn package -Pp1,p2 to run profile id with p1 and p2
Related
I use maven 3.8.5 in a web application with different layer. The parent pom is something similar to the follow:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.4.0</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>other</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
Now if I manually change the activationByDefault of dev profile from true to false and activationByDefault of other profile from false to true when I build (mvn clean package) everything goes fine.
Instead If I perform a build command like follow to obtain the same result:
mvn clean package -P other
doesn't work.. and I still find flyway library in my project. What's wrong?
I have the following profile below, instead of using activeByDefault I would like to active it through a property instead. I saw this comment (https://stackoverflow.com/a/18890159/1959534) in passing about being able to do so through maven assembly plugin but I couldn't figure out how to specify that. Any input on how to accomplish this?
<project ...>
...
<profiles>
<profile>
<id>myProfile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<!-- Extra dependency just for this profile -->
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Figured it out!
Defined a system variable in the project's /.mvn/jvm.config and then changed the activation step to be through property instead of activeByDefault. Then used this tips to throw config out to my .properties file: https://stackoverflow.com/a/14386303/1959534
jvm.config
-Dmy.property=true
pom.xml
<profiles>
<profile>
...
<activation>
<property>
<name>my.property</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
This was working for me and I'm not sure what changed.. I have my spring boot profile configured to be set based on a maven profile. The basics:
application.properties:
spring.profiles.active=#environment#
pom.xml:
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<environment>development</environment>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
<profile>
<id>production</id>
<properties>
<environment>production</environment>
</properties>
</profile>
</profiles>
When I run mvn clean package -Pdevelopment I see the line The following profiles are active: development.
Yet when I run mvn spring-boot:run -Pdevelopment I see the line The following profiles are active: #environment#.
Using the spring-boot:run command seems to not be able to resolve application property variables based on maven environment variables. Anyone know why? I tried adjusting the spring starter version without success.
According to the docs, you could tune the profiles to enable when running the application as follows:
$ mvn spring-boot:run -Dspring-boot.run.profiles=development
If not, try to comment your "spring.profiles.active" property in application.properties, that should work!
See also this thread.
Based on this tip in the docs, I added a configuration to my spring-boot-maven-plugin which broke this functionality:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
Removing the addResources configuration restores the property expansion behavior.
i m using a mac and saw this error in one of my pom file. i googled around and added the following section to the pom.xml:
<profiles>
<profile>
<id>osx</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
...
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar</systemPath>
</dependency>
...
then when i ran
mvn clean install -Posx
i still got the same error. please help!
Use the below command to install tools.jar from your installed JDK location to maven repository.
$mvn install:install-file -DgroupId=sun.jdk -DartifactId=tools -Dpackaging=jar -Dversion=1.6 -Dfile="C:\Program Files\Java\jdk1.6.0_27\lib\tools.jar"
Note: Make sure that JDK installed path correct in the above command.
I have two projects, project A is depending on project B, so normally, I'd have the following section in my projectA/pom.xml:
<dependency>
<artifactId>projectB</artifactId>
<groupId>blabla</groupId>
<version>version1</version>
</dependency>
What I am trying to achieve is very straight forward, does maven profile allow me to do anything like:
if(profileA) {
<version>version1</version>
}
else {
<version>version2</version>
}
Yes, this can be done (put activeByDefault to whichever profile you need to be default).
<dependency>
<artifactId>projectB</artifactId>
<groupId>blabla</groupId>
<version>${dependency.version}</version>
</dependency>
...
<profiles>
<profile>
<id>first</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<dependency.version>1.2.3</dependency.version>
</properties>
</profile>
<profile>
<id>second</id>
<properties>
<dependency.version>2.3.4</dependency.version>
</properties>
</profile>
</profiles>