【问题标题】:Using Provided Artifact As Maven Plugin Dependency使用提供的工件作为 Maven 插件依赖
【发布时间】:2021-04-27 00:26:45
【问题描述】:

这似乎应该是一个简单的问题,但我似乎找不到任何有关它的信息。当 maven 插件具有必需的依赖项时,是否可以告诉它使用 pom 部分中其他地方定义的工件?

例如,我正在尝试将“maven-processor-plugin”添加到我的构建中。该插件依赖于“hibernate-jpamodelgen”。我正在使用wildfly,所以我已经将该jar 作为项目的依赖项。我想确保我对两者都使用相同的版本。我正在尝试做的事情是否可能?

一些代码sn-ps:

<dependencies>
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-ejb3</artifactId>     
            <version>${version.server.bom}</version>           
            <scope>provided</scope>
       </dependency>
          
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <scope>provided</scope>
        </dependency>
</dependencies>
<build>
        <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArguments>
                    <processor>-proc:none</processor>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
           <version>4.5</version>
            <executions>
                <execution>
                    <id>process</id>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <phase>generate-sources</phase>
                    <configuration>
                        <outputDirectory>${project.build.directory}/generated-sources/java/jpametamodel</outputDirectory>
                        <processors>
                            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                        </processors>
                        <overwrite>true</overwrite>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-jpamodelgen</artifactId>
                    <!-- How do I handle this without hard coding the version? -->
                    <!-- <version>???</version> -->
                </dependency>
            </dependencies>
        </plugin>
    </build>

【问题讨论】:

    标签: maven plugins dependencies version wildfly


    【解决方案1】:

    在 POM 的 &lt;properties&gt; 部分定义类似 &lt;hibernate-jpamodelgen.version&gt; 的属性。

    然后将该属性用于类似${hibernate-jpamodelgen.version} 的版本。

    【讨论】:

    • 我想到了。问题是,hibernate-jpamodelgen 的版本号是在 wildfly pom.xml 中定义的。我可以看看我是否可以使用他们定义的任何属性,但是如果他们更改该属性的名称,我仍然冒着我的 pom 损坏的风险。
    猜你喜欢
    • 1970-01-01
    • 2015-06-12
    • 2018-08-16
    • 1970-01-01
    • 2012-08-31
    • 2019-02-06
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多