maven - 在不创建插件的情况下构建自定义 Maven 生命周期
问题描述
我需要创建一个自定义的 maven 生命周期,我想在我的应用程序的同一个 pom.xml 上执行它。可能吗?这是我拥有的相关代码和得到的结果:
<project_root>/src/main/resources/META-INF/plexus/components.xml:
<?xml version='1.0'?>
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<role-hint>Configurator</role-hint>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<configuration>
<id>Configurator</id>
<phases>
<phase>process-resources</phase>
<phase>login</phase>
</phases>
<default-phases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
</default-phases>
</configuration>
</component>
</components>
</component-set>
<project_root>/src/main/resources/META-INF/maven/lifecycle.xml:
<?xml version='1.0'?>
<lifecycles>
<lifecycle>
<id>Configurator</id>
<phases>
<phase>
<id>process-resources</id>
</phase>
<phase>
<id>configure</id>
</phase>
</phases>
</lifecycle>
</lifecycles>
<project_root>/pom.xml:
<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.luismmribeiro.config</groupId>
<artifactId>Configurator</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
结果:
>mvn 配置
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< org.luismmribeiro.config:Configurator >----------------
[INFO] Building Configurator 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.154 s
[INFO] Finished at: 2019-03-12T19:24:38Z
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "configure". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
解决方案
我建议迁移到 gradle。它提供了 maven 的几乎所有基本功能,并允许在同一个配置文件中创建用 groovy 编写的自定义任务。
推荐阅读
- c# - 无法在 C# 应用程序上找到特定于供应商的 UUID
- amazon-web-services - 创建 CloudFront 分配时“指定的密钥不存在”
- javascript - 有没有办法使用没有库的纯 javascript 将图像复制到剪贴板?
- class - Weka 中每个班级的准确性
- db2-luw - DB2 LUW - JSON_Table 将 json 数组数据读取为表格格式
- javascript - Adonis js Where 子句不起作用。此代码始终返回值 0
- python - 如何在 @ag.args 装饰器中使用 dict?
- azure - Add-AzIotHubRoutingEndpoint cmdlet
- c++ - 模板类中的 Lambda 模板变量(静态 constexpr) - 类型为 template_parm_index 的意外表达式
- sql-server - 更新表的列名及其依赖的 UDF/USP