Maven ant task wildcard exclusion does not work - maven

I just started using maven ant task, and one issue I found today was, when the pom contains wildward exclusion, seems the artifacts won’t be excluded.
My script snippet below:
Ant:
<artifact:dependencies filesetId="ls.jar.all">
<pom file="ls-jar-all.pom.xml" />
</artifact:dependencies>
Ls-jar-all.pom.xml:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.abdera</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
While changing wildcard to individual artifactIds, the exclusion works. (the wildward pom works when using maven)
Any suggestions, thanks

Related

maven cannot use correct version in verson range

I'm using maven version 3.6.2 to build my project, it has multiple layers of dependencies and finally depends on ~/.m2/repository/com/nimbusds/nimbus-jose-jwt/5.10/nimbus-jose-jwt-5.10.pom
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>[1.3.1,2.3]</version>
</dependency>
I got compile failed: com.nimbusds:nimbus-jose-jwt:jar:5.10 -> net.minidev:json-smart:jar:2.3-SNAPSHOT: Failed to read artifact descriptor for net.minidev:json-smart:jar:2.3-SNAPSHOT: Failure to find net.minidev:minidev-parent:pom:2.3-SNAPSHOT...
If I manually update ~/.m2/repository/com/nimbusds/nimbus-jose-jwt/5.10/nimbus-jose-jwt-5.10.pom to use <version>2.3</version> instead of <version>[1.3.1,2.3]</version>then it can compile fine. Why maven cannot interpret [1.3.1,2.3] correctly?
I use this to solve the program, refer https://bitbucket.org/connect2id/nimbus-jose-jwt/issues/388/json-smart-pom-23-snapshot
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>5.10</version>
<!--参考https://bitbucket.org/connect2id/nimbus-jose-jwt/issues/388/json-smart-pom-23-snapshot-->
<exclusions>
<exclusion>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.3</version>
</dependency>

Why isn't maven including a needed transitive dependency?

I am converting our Jenkins Freestyle build to Declarative Pipeline mode. I am using the same POM files.
But whenever i run the pipeline build, i see that the desired war is missing a transitive dependency. The Freestyle build includes that missing dependency however.
The Main parent POM includes:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.5.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
The second parent includes section below, :
<dependencies>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
</dependency>
</dependencies>
For both build processes, the dozer artifact is contained in the war file. But dozer contains a dependency of its own:
<dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
It is this commons-beanutils that I am missing from my final war when i do the Pipeline build. Since I am using the same POM files for both build processes, how can this be possible?
Please help

Override version of transitive dependencies in Maven

I have the following in my pom
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>org.codehaus.groovy</artifactId>
<groupId>groovy-all</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>org.codehaus.groovy</artifactId>
<groupId>groovy-all</groupId>
</exclusion>
</exclusions>
</dependency>
Basically, I want to force my second and third dependencies to use the version of groovy-all that I'm setting in my first dependency. Is there a better way to do this than setting an exclusion on each of them?
Since as a first dependency you're explicitly defining a version of the groovy-all dependency, this will override the version of this dependency for all transitive dependencies needing this exact dependency. Hence, you won't have to define explicit exclusions.
To validate this, you can run the following before and after the change:
mvn dependency:tree -Dverbose
And compare the output.
Fix is to lock down the version, either via a direct dependency, or a dependency-management section.

Maven exclusion jar is still part of war file

I am using Maven 3.0.5 and I have the following in pom.xml
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>janino</groupId>
<artifactId>janino</artifactId>
</exclusion>
</exclusions>
</dependency>
When I build war using mvn install, I can see that in war file xml-apis-1.0.b2.jar is also included although I have put xml-apis in exclusion list.
Why artifactId which is mentioned in exclusions is part of war file?
How can I make sure that xml-apis-1.0.b2.jar is not part of war the file?
Any help is highly appreciable.
Looking at maven dependency description in maven repo, I do not see any transitive dependency for antlr.
So this means the retrieved dependencies for xml-apis is coming from some other dependency in your project. Please check if this is the case.

POM for 'log4j:log4j:pom:1.2.15:compile' is invalid

Can please anyone tell me what I am doing wrong here ?
I am getting the following warnings when I run mvn install:
[WARNING] POM for 'log4j:log4j:pom:1.2.15:compile' is invalid. It will be ignored for artifact resolution. Reason: Cannot read project model from interpolating filter of serialized version. for project log4j:log4j at Artifact [log4j:log4j:pom:1.2.15:compile]
[WARNING] POM for 'log4j:log4j:pom:1.2.15:compile' is invalid. It will be ignored for artifact resolution. Reason: Cannot read project model from interpolating filter of serialized version. for project log4j:log4j at Artifact [log4j:log4j:pom:1.2.15:compile]
Pom file has:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<artifactId>mail</artifactId>
<groupId>javax.mail</groupId>
</exclusion>
<exclusion>
<artifactId>jms</artifactId>
<groupId>javax.jms</groupId>
</exclusion>
<exclusion>
<artifactId>jmxri</artifactId>
<groupId>com.sun.jmx</groupId>
</exclusion>
<exclusion>
<artifactId>jmxtools</artifactId>
<groupId>com.sun.jdmk</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
There's nothing wrong with your dependency declaration. Therefore, I would guess something went wrong during the download of the POM.
Delete the relevant folder in your local repository (e.g. .m2/repository/log4j/log4j/1.2.15) and try again.

Resources