依赖管理不适用于多模块项目

火大理石

我有一个包含多个模块的Maven项目,我正在尝试进行设置,以便将模块依赖关系自动构建到将依赖的模块构建到请求的生命周期阶段所需的正确生命周期阶段。

在该示例中,该模块plugin构建了一个Maven插件,该插件用于生成源代码,并被模块使用main如果我只是尝试使用mvn -am -pl main compileplugin则会编译模块,但process-classes不会执行生命周期阶段(这对于使用插件是必需的)。main然后,编译模块将失败,并出现以下错误:

[ERROR] Failed to parse plugin descriptor for example:plugin:1.0.0-SNAPSHOT (/Users/ims/Dropbox/IMS/Projects/PARITy_R4/codegen-test-simple/plugin/target/classes): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]

Maven或它的插件是否能够解决多模块项目中模块的依赖关系,并将其构建为其他模块必需的阶段?如果是这样,我需要如何设置项目才能使其正常工作?

这些是我的项目的POM:

pom.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>example</groupId>
    <artifactId>project</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>plugin</module>
        <module>main</module>
    </modules>
</project>

plugin / pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>example</groupId>
    <artifactId>plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>maven-plugin</packaging>
    <parent>
        <groupId>example</groupId>
        <artifactId>project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <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.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <goalPrefix>configurator</goalPrefix>
                </configuration>
                <executions>
                    <execution>
                        <id>default-descriptor</id>
                        <goals>
                            <goal>descriptor</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

main / pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>example</groupId>
    <artifactId>main</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <parent>
        <groupId>example</groupId>
        <artifactId>project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <build>
        <plugins>
            <plugin>
                <groupId>example</groupId>
                <artifactId>plugin</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>codegen</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
亚伦·迪古拉(Aaron Digulla)

如果您查看Maven生命周期参考文档,将会发现compile之前process-classes

如果要执行此步骤,则需要使用mvn -am -pl main process-classes

但我建议您始终使用mvn ... install-它也会运行测试,并确保使用的插件main实际上是您认为应该使用的插件:如果没有安装,则该构建将使用本地存储库中的旧/过时版本(Maven不会神奇地确定“哦,我的反应堆中有一个插件,我将使用它而不是本地存储库中的版本”。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章