Wednesday 10 July 2019

Maven: activeByDefault element


‘activeByDefault’ element is used to activate any profile by default.

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>
      </profile>
  
    <profile>
   <id>testing</id>
      </profile>
   
     
    <profile>
   <id>dev</id>
         <activation>
            <activeByDefault>true</activeByDefault>
         </activation>
      </profile>
   
   </profiles>
   
</project>

As you see above pom.xml file, I enabled <dev> profile by default.

You can check the same by executing the command ‘mvn help:active-profiles’.

When I execute the command ‘mvn help:active-profiles’, I seen below output.

Active Profiles for Project 'org.selflearningjava:helloworld:jar:1':

The following profiles are active:

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

When you ran ‘mvn install’ command, it install the dev profile.

Note
activeByDefault option will only work if no other profiles are active.


Previous                                                    Next                                                    Home

No comments:

Post a Comment