maven command -P parameter

Preamble:

maven 命令:clean package -Dmaven.test.skip=true -P product

 

1. The command is very simple: clear the class file, package and build, skip the test , pay attention to the last -P product, -P maven will activate the id under the <profiles> tag of the pom.xml configuration under the project is product

 

[html]  view plain copy  
 
  1. <profiles>  
  2.      <profile>  
  3.          <id>product</id>  
  4.          <properties>  
  5.              <env>product</env>  
  6.          </properties>  
  7.      </profile>  
  8. </profiles>  

 

 

2. Use the ${env} defined in the placeholder configuration above for resource filtering

 

[html]  view plain copy  
 
  1. < bulid > <!--Specify resource directory configuration whether to enable resource filtering (that is, whether to enable placeholder replacement) -->  
  2.      <resources>  
  3.           <resource>  
  4.               <directory>src/main/resources</directory>  
  5.               <filtering>true</filtering>  
  6.               <includes>  
  7.                   <include>logback.xml</include>  
  8.               </includes>  
  9.           </resource>  
  10.      </rwsources>  
  11.      <!-- variable source -->  
  12.      <filters>  
  13.         <filter>src/main/resources/log-profile-${env}.properties</filter>          
  14.       </filters>  
  15.  </build>  

 

 

3. Activate the profile through maven's setting settings (the second global activation method can be ignored. If you use <env>, this value will be overwritten)

 

[html]  view plain copy  
 
  1. <activeProfiles>  
  2.   <activeProfile>product</activeProfile>  
  3. </activeProfiles>  

 

 

Summary:
      1. The -P parameter cooperates with the resource filtering Filter, and finally uses the src/main/resources/log-profile-product.properties file
      2. This configuration file provides the corresponding value for the logback.xml file that can use placeholders

      3. Activation profile and spring profile are a bit like-minded. This configuration activation of maven can also be used in many aspects, such as snapshot repository (version) for development environment and release repository for production.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326607035&siteId=291194637