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
Related
I am working on a Dubbo project and when I digging a little deep into its source code. I found these code in Dubbo's source code:
I think this shows that my project missing the org.jboss.*package
(IDEA has mark these packages in red)
But somehow this project still working, doesn't it supposed to not working due to it has some package missing?
By the way my project is organized by gradle and the build.gradle is like this:
dependencies
{
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile group: 'org.apache.dubbo', name: 'dubbo-spring-boot-starter', version: '2.7.8'
compile group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.6.2'
compile group: 'org.apache.curator', name: 'curator-framework', version: '5.1.0'
}
If this wouldn't be some library's de-compiled byte-code but your application's source code, this would rather be an issue. And it's not missing anything, but Gradle will pull in org.jboss.netty on demand, which will then pull in another 8 libraries, which may evetually even pull in further libraries.
I have a Copy task set as follow:
task copyToLib( type: Copy ) {
into "$buildDir/myapp/lib"
from configurations.runtime
// We only want jars files to go in lib folder
exclude "*.exe"
exclude "*.bat"
exclude "*.cmd"
exclude "*.dll"
// We exclude some lib
exclude group: "org.slf4j", name: "slf4j-api", version: "1.6.2"
}
And i'm getting the following error:
Could not find method exclude() for arguments [{group=org.slf4j, name=slf4j-api, version=1.6.2}] on task ':copyToLib' of type org.gradle.api.tasks.Copy
I have the feeling that it's only a syntax issue, any hint?
Exclude by group: exclude group: org.slf4j
Exclude by module: exclude module: slf4j-api
Exclude by file name: exclude { it.file.name.contains('slf4j-api') }
Exclude a file: exclude "slf4j-api.jar"
You can exclude by group and module but it needs to go into configurations exclude like this. Then it's gonna restrict the configuration before copying.
task copyToLib( type: Copy ) {
into "$buildDir/myapp/lib"
from configurations.runtime {
exclude group: 'org.slf4j'
}
// We only want jars files to go in lib folder
exclude "*.exe"
exclude "*.bat"
exclude "*.cmd"
exclude "*.dll"
}
And remember to make sure that the directory exists $buildDir/myapp/lib
And maybe instead of excluding all other files just include jars?
Maybe write a method to help you
static String generateExcludeJar(Map<String, String> map) {
"$map.name-${map.version}.jar"
// All jar names are like name-version.jar when downloaded by Gradle.
}
exclude generateExcludeJar(group: "org.slf4j", name: "slf4j-api", version: "1.6.2")
For Gradle 7.4 with Groovy:
task copyLibs(type: Copy){
from configurations.externalLib{
into '<dest-dir-name>'
exclude('slf*.jar', '<other jars if needed>')
}
}
FYI:
configurations {
externalLib.extendsFrom(implementation)
}
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?
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'
I'm using Gradle in my Android application an I would like to use the JScience library dependency. I have added the library this way:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'org.jscience:jscience:4.3.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
But in the compile time I get the error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Ljavax/realtime/MemoryArea;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
This is caused because of duplicating javax.realtime packages in project, one is a part of JDK, and the second one is in the Jscience library. I have tried to remove this package from Jscience library this way in Gradle:
sourceSets {
main {
java {
exclude 'javax/realtime/**'
}
}
}
configurations {
all*.exclude group: 'javax.realtime'
}
But that didn't help. So, that package is still exists in dependencies.
Is there any way how I can exclude a package from jar on compile time?
In case anybody needed, the problem was in Javolution dependency from JScience library. They both do hava a javax.runtime package. Excluding the Javolution has fixed the issue for me.
compile ('org.jscience:jscience:4.3.1') {
exclude group: 'org.javolution', module: 'javolution'
}