Maven Project version number
- Default version number: 1.0-snapshot The best practice is to contract the version to an unstable version if the release must be deleted;
- Recommended version rule: Major version number. The minor version number. Delta Version number-< milestone version > such as: 1.0.0-release 10.2.5-final, etc. best practice is to develop a version number rule that everyone recognizes as a combination of their own.
Common commands
The built-in MAVEN plugin provides a common command to find the corresponding package in the following location:. m2\repository\org\apache\maven\plugins
- Compile
- Clean delete/target, delete compiled binaries, etc.
- Test test Case Junit/testng
- Package Packaging
- Install the project to the local warehouse
- Deploy release jar to remote server
- MVN Help:system Viewing environment variables
Plug-in Repository
- https://maven.apache.org/plugins/
- Http://www.mojohaus.org/plugins.html
Common plugins
- findbugs Static code check
- versions Unified upgrade version number Unified upgrade version http://www.mojohaus.org/versions-maven-plugin/you can see the usage examples, Common settings version of the command for MVN versions:set–dnewversion=1.1.0-final
- mvn versions:set-dnewversion=1.1
- Source Packaging sources Use the
- assembly Package zip, war
- tomcat7
When the jar is available externally
<plugins> <!--static code bug Scan--<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>3.0.0</version> <configu Ration> <threshold>High</threshold> <effort>Default</effort> & Lt;findbugsxmloutput>true</findbugsxmloutput> <findbugsxmloutputdirectory>target/site</findbu Gsxmloutputdirectory> </configuration> </plugin> <!--version number management--<plugin> & Lt;groupid>org.codehaus.mojo</groupid> <artifactId>versions-maven-plugin</artifactId> & Lt;version>2.3</version> </plugin> <!--packaging source codes--<plugin> <artifactid>mave n-source-plugin</artifactid> <version>2.3</version> <executions> <exec Ution> <id>attach-sources</id> <phase>install</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </ Executions> </plugin> <!--This is a bit dizzy, generate executable jar package what--<plugin> <artifactid>maven-asse mbly-plugin</artifactid> <version>3.0.0</version> <configuration> <arc Hieve> <manifest> <mainClass>com.xlx.Test</mainClass> </manifest> </archieve> <descriptorRefs> <descriptorref>jar -with-dependencies</descriptorref> </descriptorRefs> </configuration> </PLUGIN&G T <!--Tomcat plug-in <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifacti D>tomcat7-maven-plugin</artifactid> <version>2.2</version> <configuration> <port>8 080</port> <path>/</path> </configuration> </plugin></plugins>
Custom Plugins
Learning Address https://maven.apache.org/guides/plugin/guide-java-plugin-development.html
- Create a project
- Modifying the POM
<packaging>maven-plugin</packaging>
- Add dependency
<dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>LATEST</version> </dependency> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <version>LATEST</version> <scope>provided</scope> </dependency></dependencies>
- Write code implementation
AbstractMojo
@Mojo(name="xlxTest",defaultPhase = LifecyclePhase.PACKAGE)public class Test extends AbstractMojo { /** * 接收的参数 */ @Parameter private String message; /** * 接收多个值的参数 */ @Parameter private List<String> options; /** * 命令行中接收,注意必须有property mvn:package -Dargs=this is from cmd */ @Parameter(property = "args") private String args; public void execute() throws MojoExecutionException, MojoFailureException { System.out.println("my first maven plugin message is : " + message); System.out.println("my first maven plugin options is : " + options); System.out.println("my first maven plugin args from evm is : " + args); }}
- MVN Install
- Use, maven can receive parameters, or use environment variables, such as ${settings.localrepository},${project.baseuri}, etc.
<!--项目pom修改--><build> <plugins> <plugin> <groupId>com.xlx</groupId> <artifactId>engineering</artifactId> <version>1.0-SNAPSHOT</version> <executions> <execution> <phase>package</phase> <goals> <goal>xlxTest</goal> </goals> </execution> </executions> <configuration> <message>message</message> <options> <option>one</option> <option>two</option> </options> </configuration> </plugin> </plugins></build>
Profile
- Different operating environment dev/prod/test, etc.
- MVN Clean Package–p Dev
- Settings.xml can specify different server warehousing configurations
<profile.active>私服或者官方</profile.active>
Configuration file path for multi-environment configuration
<profiles> <profile> <id>dev</id> <properties> <profile.active>dev</profile.active> </properties> <activation> < ;activebydefault>true</activebydefault> </activation> </profile> <profile> <id>test</id> <properties> <profile.active>test</profile.active> &L t;/properties> </profile></profiles><build> <resources> <resource> <directory>${baseDir}/src/main/resources</directory> <excludes> <exclude& gt;conf/**</exclude> </excludes> </resource> <resource> <d Irectory>src/main/resources/conf/${profile.active}</directory> </resource> </resources>< /build>
Private Servers
- Download: https://www.sonatype.com/download-oss-sonatype?hsCtaTracking=920dd7b5-7ef3-47fe-9600-10fecad8aa32% 7cf59d5f10-099f-4c66-a622-0254373f4a92
- Installation, decompression, if you need to modify the port number and other information, you can modify the file \nexus-3.13.0-01\etc\nexus-default.properties
- Start command go to \nexus-3.13.0-01\bin, Nexus/run can view boot log
- Use: http://books.sonatype.com/nexus-book/reference3/index.html
Adding a publishing node to the POM
<distributionManagement> <repository> <id>nexus-release</id> <name>nexus-release</name> <url>http://localhost:8099/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshot</id> <name>nexus-snapshot</name> <url>http://localhost:8099/repository/maven-snapshots/</url> </snapshotRepository></distributionManagement>
Modify settings.xml Add server account password information
<server> <id>nexus-release</id> <username>admin</username> <password>admin123</password></server><server> <id>nexus-snapshot</id> <username>admin</username> <password>admin123</password></server>
Build Scaffolding
- MVN Archetype:create-from-project build Scaffolding from Project
- Cd/target/generated-soource/archetype go to this directory
- MVN Install release to warehouse
- List of scaffolding that can be added to the IDE
- MVN archetype:generate–darchetypecatagory=local Command-line method to create a project local parameter specify walk-in warehouse
Two The practice of Java Engineering--maven