用户工具

站点工具


linux:maven

archetype

mvn archetype:create-from-project
mvn install -f target/generated-sources/archetype/pom.xml
mvn archetype:generate -DarchetypeCatalog=local

svn co svn://xlongwei.com/archetypes --username harry --password harryssecret
mvn install -f archetypes/pom.xml
mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=com.xlongwei.archetypes

mvn archetype:generate -DarchetypeCatalog=http://nexus.xlongwei.com/content/repositories/releases/archetype-catalog.xml -DarchetypeGroupId=com.xlongwei.archetypes
#-DarchetypeArtifactId=webapp-archetype | mydubbo-archetype | mydubbox-archetype | contentserver-archetype

deploy

mvn deploy -DaltDeploymentRepository=releases::default::http://nexus.xlongwei.com/content/repositories/releases/
mvn install:install-file -DgroupId=apijson.orm -DartifactId=apijson-orm -Dversion=4.1.0 -Dpackaging=jar -Dfile=apijson-orm-4.1.0.jar

常用命令

mvn dependency:tree //依赖树
mvn dependency:sources //下载源码
mvn dependency:resolve -Dclassifier=javadoc  //下载文档
mvn package -Dmaven.test.skip=true -DskipTests //前者跳过测试代码的编译,后者仅跳过测试代码的执行
mvn test-compile test -Dmaven.test.skip=false -Dtest=class#method
mvn exec:java -Dexec.mainClass=class -Dexec.args="arg1 arg2"

pom.xml

repositories.repository.snapshots.updatePolicy=daily每天,always实时,never从不,interval:xxx间隔分钟

settings.xml

mirrorOf:*匹配全部;repo1,repo2匹配两个;*,!repo1排除repo1
mvnd -o -s ~/.m2/settings.xml // 清除所有_remote.repositories即可离线构建
find ~/.m2/repositories -name _remote.repositories -exec rm {} \;

lifecycle

clean
validate
compile
test
test-compile
package
verify
install
site
deploy

plugin

org.apache.maven.pluginsorg.codehaus.mojo checkstyle

maven-antrun-plugin 用于迁移Ant项目
maven-archetype-plugin 项目骨架快速生成
maven-assembly-plugin 项目分发打包assembly.xml
maven-dependency-plugin 分析项目依赖
maven-enforcer-plugin 设定禁止SNAPSHOT等规则,绑定到validate阶段
maven-help-plugin 帮助信息help:effective-settings
maven-release-plugin 版本发布,依赖SCM信息,prepare检查perform构建发布
maven-resources-plugin 处理资源文件,支持根据环境或Profile过滤{property}
maven-source-plugin 打包源码,mvn source:jar install
maven-surefire-plugin 执行测试
build-helper-maven-plugin 遗留项目add-source(不推荐)
exec-maven-plugin 执行程序
jetty-maven-plugin 运行web项目,添加pluginGroup=org.mortbay.jetty
versions-maven-plugin 管理版本mvn versions:set -DnewVersion=1.1-SNAPSHOT
maven-checkstyle-plugin 代码检查 mvn checkstyle:check
maven-pmd-plugin 代码检查 mvn pmd:check
spotbugs-maven-plugin 错误查找 mvn spotbugs:check

jar

mvn compile resources:resources jar:jar
mvn dependency:copy-dependencies -DoutputDirectory=target
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<configuration>
		<archive>
			<manifest>
				<mainClass>${project.main.class}</mainClass>
				<addClasspath>true</addClasspath>
			</manifest>
		</archive>
	</configuration>
</plugin>
scp user@host:/home/user

mvnd

mvnd releases

git clone https://github.com/apache/maven-mvnd.git
mvn clean verify -Pnative  //可以直接下载release
mvnd -v //-h帮助
mvnd --status //--stop停止
linux/maven.txt · 最后更改: 2022/04/21 09:51 由 admin