maven的profiles功能介绍、maven自定义插件plugin
profiles
maven配置文件的profiles功能类似于springboot的spring.profiles.active配置,指定不同的环境来读取相应的配置内容。 <profiles>标签的子标签可以包含<repository> <plugin> <dependencies> <distributionManagement>等。
触发激活配置可以是:
-
命令行 mvn -p prod xxx 默认配置 <activeByDefault>true</activeByDefault>
详情查看
自定义maven插件plugin
- 创建maven项目
- pom文件设置: <artifactId>demo-ssx</artifactId> <packaging>maven-plugin</packaging> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <version>3.1</version> </dependency> </dependencies>
- 继承Mojo插件的抽象类实现方法 package ssx; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @Mojo(name="hello",defaultPhase = LifecyclePhase.CLEAN) public class SsxMojo extends AbstractMojo { @Parameter private String test; //真正执行的方法 @Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().warn("ssx 自定义plugin:"+test); getLog().warn("ssx 自定义plugin:"+test); getLog().warn("ssx 自定义plugin:"+test); getLog().warn("ssx 自定义plugin:"+test); } }
- 把此工程打包发布 mvn install deploy
- 使用 在另一个工程中pom文件引入此plugin <plugins> <plugin> <groupId>org.example</groupId> <artifactId>demo-ssx</artifactId> <version>1.0-SNAPSHOT</version> <executions> <execution> <goals> <goal>hello</goal> </goals> </execution> </executions> <configuration> <test>你好你好你好</test> </configuration> </plugin> </plugins> 执行命令mvn demo-ssx:hello或者idea中右侧maven的plugin选项
