Java – can I use the same POM Redefine imported Maven dependencies in XML?

I'm working in an application server environment, and I'm using BOM to collect dependency information, as follows:

<dependency>
            <groupId>org.jboss.bom.eap</groupId>
            <artifactId>jboss-javaee-6.0-with-security</artifactId>
            <version>${jboss.bom.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

However, this particular BOM specifies the dependency as "compiled", and I want to set the scope of all projects to "provided" However, when I try to override the scope in the same POM, I import the dependencies as follows:

<dependency>
            <groupId>org.picketlink</groupId>
            <artifactId>picketlink-federation</artifactId>
            <scope>provided</scope>
        </dependency>

Maven complains that it can't find the version, or if I use the version attribute specified in BOM, I can't find it

I'm sure this is the problem of importing coverage in the same POM, because I can cover the scope in the subproject Is there any way to import and coverage in a POM?

*All the code snippets above come from the same part

Solution

This is certainly feasible:

<dependencyManagement>
   ...
   <dependency>
     <groupId>org.jboss.bom.eap</groupId>
     <artifactId>jboss-javaee-6.0-with-security</artifactId>
     <version>${jboss.bom.version}</version>
     <type>pom</type>
     <scope>import</scope>
   </dependency>
   ...
</dependencyManagement>
<dependencies>
   ...
   <dependency>
     <groupId>org.picketlink</groupId>
     <artifactId>picketlink-federation</artifactId>
     <scope>provided</scope>
   </dependency>
</dependencies>

Remember that you need to redefine the scope in < dependencies >, not in < dependencymanagement > part.

If inheritance is used, coverage is certainly propagated to any child POM

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>