我需要创建一个自定义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
如果您的替换命令和shell命令应该在正常构建期间发生,我会将它们添加到标准构建周期的适当阶段。
如果它们形成一个单独的动作,我会写一个Maven插件。
我从未见过使用自定义生命周期的问题解决方案,也无法说明这是否可行。
我建议迁移到gradle。它提供了maven的几乎所有基本功能,并允许在同一配置文件中创建以groovy编写的自定义任务。