Gradle plugin-publish plugin is skipping dependency excludes - gradle

I have some transitive dependency excludes in my custom-plugin build script. Like so:
configurations {
compile.exclude group: 'commons-math3', module: 'commons-math3'
}
dependencies {
'org.apache.jmeter:ApacheJMeter:2.13',
}
When publishing to plugins.gradle.org using com.gradle.plugin-publish version 0.9.1, the excludes are not propagated to the generated POM:
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter</artifactId>
<version>2.13</version>
<scope>compile</scope>
</dependency>
Is there a workaround? Can I somehow use plugin-publish's withDependencies extension?
Maven-publish plugin has (or at least, used to have) a similar issue. See here
Update: This issue is unresolved, and is now logged as a gradle defect.

Exclude the module at the dependency that it is a transitive dependency of:
dependencies {
compile('org.apache.jmeter:ApacheJMeter:2.13') {
exclude group: 'commons-math3', module: 'commons-math3'
}
}
And this is what you will get in the resulting POM:
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter</artifactId>
<version>2.13</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>commons-math3</artifactId>
<groupId>commons-math3</groupId>
</exclusion>
</exclusions>
</dependency>

Related

how to use apache-maven-shade plugin to resovle multi dependency conflict

Maven shade plugin is very powerful for resolving dependency conclict, but a situation I have is as follows :
myproject
guava 31
thridparty-dependency-1
guava18
I could relocate the guava 31 dependency and then the conflict will be resolved. And how about following situation :
myproject
thirdparty-1
guava31
thirdparty-2
guava18
thirdparty-3
guava4
Or how about if there are more than two dependencies conflicting as the same dependency but with different versions ?
If I use relocation, then thirdparty-1/guava31 will be relocated but the guava18 and guava4 still conflict.
I'm not sure how to handle this situation.
You need to de-conflict these across the whole project, not just for the shaded uber-jar.
Use Maven <exclusions> in the pom.xml declarationtion to achieve this.
For example:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>${neo4j.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>${netty.version}</version>
</dependency>

Gradle dependency with test classifier

I've been trying to reference an artefact without luck.
With maven I have no problem doing this:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.13</artifactId>
<version>3.0.0</version>
<classifier>test</classifier>
</dependency>
Maven selects the correct artefact.
However, with gradle, it always seems to include the artefact without the classifier, no matter what I try:
implementation 'org.apache.kafka:kafka_2.13:3.0.0:test'
I have read the gradle documentation and it suggests this syntax, maybe it has something to do with this specific artefact?
Update
My goal is to use spring-kafka-test. Our internal artefact repository is not set up to use pom resolution, which is why I need to add transitives manually.
I've ruled out the fact that it might be our internal repository by only using maven central; and I get the same results.
I managed to include only the mentioned jar, with:
dependencies {
implementation ('org.apache.kafka:kafka_2.13:3.0.0:test') {
exclude group: 'org.apache.kafka' // or finer grained, if we like
}
...
}
See also: How to specify a classifier in a gradle dependency's dependency?
But
Your assumptions about maven were also wrong:
Maven pulls all! (In module-test-parents no dependencies defined.)
To achieve the same (and even more) in maven we'd also have to:
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.13</artifactId>
<version>3.0.0</version>
<classifier>test</classifier>
<exclusions>
<exclusion> <!--sledge hammer -->
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
<!-- or selectively ... -->
</exclusions>
</dependency>
</dependencies>
In gradle the according would be (tested):
implementation ('org.apache.kafka:kafka_2.13:3.0.0:test'){
exclude group: '*'
}

BIRT maven configuration not working

BIRT maven configuration not working as expected.
Added following dependencies in the pom.xml file
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.4.2</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>com.ibm.icu</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
<version>3.4.0.v20140312-2051</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>com.ibm.icu</artifactId>
<version>52.1.1.v201501240615</version>
</dependency>
the jar has been downloaded and Maven update was done on the project. Still, java code gives compile time error?
import org.eclipse.birt.report.engine.api.*;
Compile time error: The import org.eclipse cannot be resolved
How can we resolve these dependencies and make it work?
You are just importing the runtime library, not the engine api. Therefore, your compiler complains about missing classes.
You need the following library to import:
https://mvnrepository.com/artifact/org.eclipse.birt/report-engine/3.7.0
Finally, I am able to use by doing some changes in dependencies
Add these two jars in lib folder.
"flute-1.3.jar" &
"org.eclipse.orbit.mongodb-2.10.1.v20130422-1135.jar"
Dependency Update:
//Start of birt
compile(group: 'org.eclipse.birt.runtime', name: 'org.eclipse.birt.runtime', version: '4.4.2') {
exclude(group: 'org.milyn', module: 'flute')
exclude(group: 'org.eclipse.birt.runtime', module: 'org.eclipse.orbit.mongodb')
}
//End of birt

Excluding transitive dependency from Maven pom

I have a Maven dependency added where type is test-jar and scope is test. I want to remove a transitive dependency from this (because in the Nexus prod repo this dependency is missing which leads to Jenkins build failure). I have added a exclusion tag but still the dependency is not removed i.e. Jenkins build still fails and complains about this dependency. Any clue why?
<dependency>
<groupId>com.xxx</groupId>
<artifactId>xxx</artifactId>
<type>test-jar</type>
<version>${xxx.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>jamon</artifactId>
<groupId>com.jamonapi</groupId>
<!-- <scope>compile</scope> -->
</exclusion>
</exclusions>
</dependency>
You can use the following command to find out the transitive dependency details and then you can exclude the dependency:
mvn dependency:tree -Dverbose -Dincludes=<artifact_name>

spring boot starter test 1.4.1 - use assertj-core 3.5.x

I want to use the latest assertj-core for Java8 (for example to assert on optionals).
I use spring-boot-starter-test 1.4.1 it comes with assertj 2.5.0 preconfigured.
I cannot use a spring boot parent pom.
How can I set up my maven project, so I exclude or overwrite version 2.5.0 with 3.5.2? I tried
setting just the property assertj.version
adding exclusions on the starter-test dependency
adding exclusion on the spring-boot-dependencies
Update:
I am setting up a custom "test" module for all modules in my multi module project. I do not just need spring-test-starter but also some other dependencies and some test classes and rules.
This is what my project looks like:
my-module-root
|-my-module-a (using test)
|-my-module-b (using test)
\-test (including starter-test, ... - in COMPILE scope (because this is a test library))
Now, when I exclude assertj-core on the test module (and include 3.5.2), the dependencies for the test module are ok.
But when I check the dependencies on the root level, I have both, assertj-core-2.5.0 and assertj-core-3.5.2 on the classpath.
You can exclude it from spring-boot-starter-test and then add manually different version:
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
To verify which version is included:
$ mvn dependency:tree | grep assertj
[INFO] \- org.assertj:assertj-core:jar:3.5.2:test

Resources