Wednesday 10 July 2019

Maven: Display all active profiles


'mvn help:active-profiles' list all the active profiles from the pom.

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>org.selflearningjava</groupId>
   <artifactId>helloworld</artifactId>
   <packaging>jar</packaging>
   <version>1</version>
   <name>helloworld</name>
   <url>http://maven.apache.org</url>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>
   </dependencies>
   
   <profiles>
   
      <profile>
   <id>production</id>
         <activation>
            <activeByDefault>false</activeByDefault>
            <jdk>1.8</jdk>
            <os>
               <name>Windows XP</name>
               <family>Windows</family>
               <arch>x86</arch>
               <version>5.1.2600</version>
            </os>
            <property>
               <name>myAppVersion</name>
            </property>
         </activation>
      </profile>
  
    <profile>
   <id>testing</id>
         <activation>
            <activeByDefault>false</activeByDefault>
            <jdk>1.8</jdk>
         </activation>
      </profile>
   
   </profiles>
   
</project>


I am running on Windows 10 machine and jdk1.8.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.selflearningjava:helloworld >-------------------
[INFO] Building helloworld 1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.0.1:active-profiles (default-cli) @ helloworld ---
[INFO]
Active Profiles for Project 'org.selflearningjava:helloworld:jar:1':

The following profiles are active:

 - snapshot.build (source: external)
 - sonar (source: external)
 - testing (source: org.selflearningjava:helloworld:1)



[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.539 s
[INFO] Finished at: 2018-04-24T13:46:42+05:30
[INFO] ------------------------------------------------------------------------

As you see the output, ‘testing’ profiles is also included in active profiles list.

Let’s change the java version from 1.8 to 1.7 and rerun the command.

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>org.selflearningjava</groupId>
   <artifactId>helloworld</artifactId>
   <packaging>jar</packaging>
   <version>1</version>
   <name>helloworld</name>
   <url>http://maven.apache.org</url>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>
   </dependencies>
   
   <profiles>
   
      <profile>
   <id>production</id>
         <activation>
            <activeByDefault>false</activeByDefault>
            <jdk>1.8</jdk>
            <os>
               <name>Windows XP</name>
               <family>Windows</family>
               <arch>x86</arch>
               <version>5.1.2600</version>
            </os>
            <property>
               <name>myAppVersion</name>
            </property>
         </activation>
      </profile>
  
    <profile>
   <id>testing</id>
         <activation>
            <activeByDefault>false</activeByDefault>
            <jdk>1.7</jdk>
         </activation>
      </profile>
   
   </profiles>
   
</project>


Execute the command ‘mvn help:active-profiles’.

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.selflearningjava:helloworld >-------------------
[INFO] Building helloworld 1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.0.1:active-profiles (default-cli) @ helloworld ---
[INFO]
Active Profiles for Project 'org.selflearningjava:helloworld:jar:1':

The following profiles are active:

 - snapshot.build (source: external)
 - sonar (source: external)



[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.244 s
[INFO] Finished at: 2018-04-24T13:47:46+05:30
[INFO] ------------------------------------------------------------------------


Previous                                                    Next                                                    Home

No comments:

Post a Comment