gradle exclude transient dependency from project - java

In my build.gradle I have the following snipped:
dependencies {
compile project(':utils')
compile (project(':cache')) {
// excludings because of dropwizard conflicts
exclude group: 'org.glassfish.jersey.core'
exclude group: 'javax.ws.rs'
exclude group: 'com.codahale.metrics'
}
but in fact the artifacts are not excluded I still end up with different jersey and metrics in my classpath. Ony if I put this in my cache/build.gradle it will compile and run.
configurations {
all*.exclude group: 'com.codahale.metrics'
all*.exclude group: 'org.glassfish.jersey.core'
}
But then my cache project is broken because of missing dependencies which is not what I wanted.

I've had issues with this in the past, what worked was when I included module: explicitly along with the group. like so:
exclude group: 'commons-math3', module: 'commons-math3'
If you use configurations to exclude, you don't have to do it on all*, you can do it on just local project compile as :
compile.exclude group: 'commons-math3', module: 'commons-math3'

Related

Intellij GWT configuration. NoSuchMethodError on module compilation

I'm trying to debug my client-side code from IntelliJ.
Currently i build the project using this gradle plugin: https://github.com/steffenschaefer/gwt-gradle-plugin.
This is the gradle task:
task oneClickGwtSuperDev(type:de.richsource.gradle.plugins.gwt.GwtSuperDev){
group = "gwt"
workDir = file("$buildDir/gwt/work")
noPrecompile = true
bindAddress = '127.0.0.1'
launcherDir = file("$projectDir/devWar")
logLevel = 'INFO'
port = 9876
sourceLevel = '1.8'
}
This depends on another task that starts a tomcat container, therefore i'm not using the embedded server.
My goal is to stop using the gradle task for develpment, and create a GWT configuration in intellij, in order to debug from the IDE, and not the browser.
This is what i've tried:
The codeserver starts, but when module compiles i get a NoSuchMethodError.
Caused by: java.lang.NoSuchMethodError: com.google.gwt.core.ext.linker.GeneratedResource.setPrivate(Z)V
at org.atmosphere.gwt20.rebind.SerializerGenerator.generateIncrementally(SerializerGenerator.java:134)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:739)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:103)
My assumption is, when i build with the GWT configuration, the dependencies are messed up.
The working configuration (Gradle) has some excludes in the dependencies, and i think my problem is related to this.
providedCompile ('com.google.gwt:gwt-dev:' + mambu.versions.gwt) {
exclude group: 'com.google.code.gson', module: 'gson'
exclude group: 'commons-collections', module: 'commons-collections'
exclude group: 'org.apache.commons', module: 'commons-lang3'
exclude group: 'commons-io', module: 'commons-io'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
providedCompile('com.google.gwt:gwt-user:' + mambu.versions.gwt) {
exclude group: 'javax.validation', module: 'validation-api'
}
Any ideas?

How to exclude a jar from gradle

I try to exclude a jar from gradle build but how to do that for my project part I am not clear.Below are the dependencies I have to exclude only geronimo-javamail_1.4_spec/1.7.1 jar because which gives error when I try to send mail.Please give your guidance to solve this.
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-batch")
//compile("org.springframework.boot:spring-boot-devtools")
compile('org.apache.commons':'commons-lang3':'3.5'){
exclude module: 'geronimo'
}
compile group: 'org.apache.cxf', name: 'cxf-spring-boot-starter-jaxws', version: '3.1.10'
compile group: 'org.apache.cxf', name: 'cxf-rt-ws-security', version: '3.1.10'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
update:exclusion is not working
First of all, there is an issue with this statement:
compile('org.apache.commons':'commons-lang3':'3.5')
If you want to use the colon notation for a dependency, it has to be all in one String, like so:
compile('org.apache.commons:commons-lang3:3.5')
Also, you should probably use the full module name: module: 'geronimo-javamail_1.4_spec'.
Finally, geronimo-javamail_1.4_spec is a transitive dependency of more than one dependency in this setup, so you should exclude it everywhere where necessary one by one, or exclude it altogether like so:
configurations {
all*.exclude module: 'geronimo-javamail_1.4_spec'
}
This should be added in your build.gradle file at the same level as the dependencies{} section, not within it, so the final code would look like this:
configurations {
all*.exclude module: 'geronimo-javamail_1.4_spec'
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-batch")
//compile("org.springframework.boot:spring-boot-devtools")
compile('org.apache.commons:commons-lang3:3.5')
compile group: 'org.apache.cxf', name: 'cxf-spring-boot-starter-jaxws', version: '3.1.10'
compile group: 'org.apache.cxf', name: 'cxf-rt-ws-security', version: '3.1.10'
testCompile('org.springframework.boot:spring-boot-starter-test')
}

Android Tests don't run on a device lower than 5 (API 21) NoClassDefFoundError

I am trying to run Instrumental tests for my project. But they don't run on devices(emulators as well) that have version lower than 5 (API 21).
I have been trying to solve this problem, but still facing with it.
I get following exception.
02-15 10:46:08.965 1127-1143/? E/AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner
java.lang.ExceptionInInitializerError
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:81)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:524)
at android.support.test.runner.AndroidJUnitRunner.createTestRequestBuilder(AndroidJUnitRunner.java:379)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:352)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:269)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
Caused by: java.lang.NoClassDefFoundError: org.junit.runner.manipulation.Filter$1
at org.junit.runner.manipulation.Filter.<clinit>(Filter.java:21)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:81) 
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:524) 
at android.support.test.runner.AndroidJUnitRunner.createTestRequestBuilder(AndroidJUnitRunner.java:379) 
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:352) 
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:269) 
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584) 
I have already tried all solutions for similar questions.
Here how my project structure looks.
And gradle dependencies for tests
/************* TEST STUFF ***************/
androidTestCompile 'junit:junit:4.12'
androidTestCompile fileTree(include: ['robotium-solo-5.5.2.jar'], dir: 'libs')
//mockito dependencies
androidTestCompile 'org.mockito:mockito-core:2.7.6'
androidTestCompile files('libs/dexmaker-mockito-1.0.jar')
androidTestCompile files('libs/dexmaker-1.0.jar')
// Set this dependency to build and run Espresso tests
androidTestCompile('com.android.support.test.espresso:espresso-core:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to use JUnit 4 rules
androidTestCompile('com.android.support.test:rules:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
//MockWebServer - Version 2.2 of mockwebserver doesn't work because of an issue, so forcing v2.1 - https://github.com/square/okhttp/issues/1069
androidTestCompile('com.squareup.okhttp3:mockwebserver:+') {
exclude module: 'okhttp'
}
androidTestCompile "org.slf4j:slf4j-api:1.7.12"
//WireMock
androidTestCompile("com.github.tomakehurst:wiremock:2.5.0") {
//Using Android Version Instead
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
//Version conflict with our app's slf4j version
exclude group: 'org.slf4j', module: 'slf4j-api'
//Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
exclude group: 'org.ow2.asm', module: 'asm'
//Was getting this warning, so decided to ignore this version included by WireMock.
//Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
//In case of problem, please repackage with jarjar to change the class packages
exclude group: 'org.json', module: 'json'
}
androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
And BaseTestClass have the following structure
#RunWith(AndroidJUnit4.class)
public abstract class InstrumentalSuperTest {
private SystemAnimations mSystemAnimations;
#Rule
public IntentsTestRule rule = provideActivity();
#Rule
public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.wireMockConfig().port(BuildConfig.PORT), false);
protected abstract IntentsTestRule provideActivity();
}
And this happens not only with my project, but with Wiremock examples as well, the same error.
Maybe I run test incorrectly, I just click on a test class and choose Run ... Test.
Please help to solve this problem, I have no idea what is wrong.
You may try newer version of wiremock. later than 2.0.8-beta.
for more about this have a look at this stackoverflow answer

Cannot exclude module from build.gradle

I'm trying to exclude some modules from my build.gradle file but it(code1 and code2) still downloads the excluded files.
code 1:
compile (group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.7') {
exclude group: 'com.amazonaws', module: 'aws-java-sdk-machinelearning'
}
code 2:
compile (group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.7') {
exclude module: 'aws-java-sdk-machinelearning'
}
when I tried using the following code,
configurations {
compile.exclude module: 'aws-java-sdk-machinelearning'
}
it excludes the files but I don't want to use this method to exclude files
I second/confirm with #Opal that code1 works fine in Gradle 2.13.
What is likely happening is that you have some other (maybe non-aws) dependency, that may be transitively using aws-java-sdk which then brings in the machine-learning dependency. Which is why, it works fine when you do a global exclude, but not when you do a local exclude on just aws-java-sdk.
Try running gradlew dependencies --configuration=compile to get a tree of dependencies, including transitives, to check which dependency might be bringing in aws-java-sdk-machinelearning

Mac unable to resolve dependencies with gradle

I have a simple build.gradle that pulls in a few java dependencies. On my mac, gradle keeps saying that its unable to resolve dependencies for any jar. This only started happening yesterday, rebooting doesn't solve this. I have tried running the project on linux and things work just as expected. Any idea whats up with my mac thats causing this?
Cause 2: java.lang.InternalError
[...]
at javax.xml.parsers.SecuritySupport$4.run(SecuritySupport.java:92)
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.parsers.SecuritySupport.getResourceAsStream(SecuritySupport.java:87)
at javax.xml.parsers.FactoryFinder.findJarServiceProvider(FactoryFinder.java:288)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:255)
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:121)
at org.apache.ivy.util.XMLHelper.getDocBuilder(XMLHelper.java:208)
at org.apache.ivy.util.XMLHelper.parseToDom(XMLHelper.java:193)
at org.apache.ivy.plugins.parser.m2.PomReader.<init>(PomReader.java:95)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.GradlePomModuleDescriptorParser.parseDescriptor(GradlePomModuleDescriptorParser.java:91)
[...]
Caused by: java.util.zip.ZipException: error in opening zip file
When I run on linux, things are working fine.
Here is my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.7'
}
apply plugin: 'scala'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.10.3'
compile('com.twitter:finagle-core_2.10:6.9.0') {
exclude group: 'junit', module: 'junit'
exclude group: 'org.mockito', module: 'mockito-all'
exclude group: 'org.scala-tools.testing', module: 'specs_2.10'
exclude group: 'org.scalatest', module: 'scalatest_2.10'
}
compile('com.twitter:finagle-http_2.10:6.9.0') {
exclude group: 'junit', module: 'junit'
exclude group: 'org.mockito', module: 'mockito-all'
exclude group: 'org.scala-tools.testing', module: 'specs_2.10'
exclude group: 'org.scalatest', module: 'scalatest_2.10'
}
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.3.0'
}
Using Java 7 and Gradle 1.7
Try dropping maven and/or gradle cache for the dependencies that make problems or just altogether:
rm -rf ~/.gradle/
rm -rf ~/.m2/repository/
Please note that the later may lead to significant network traffic and build times next time the build is run!
Turns out my java got corrupted; reinstalling java fixed the issue

Categories