I've inherited some code and want to add cucumber to the project, preferably changing as little as possible. But the gradle file has a configuration level setting to stop transitive dependencies being pulled in, which is causing cucumber-java to not pull in cucumber-core and therefore fail.
So here's the relevant parts of build.gradle:
configurations.all {
transitive = false
}
depdendencies {
compile(group: .... lots of these
testCompile(group: 'io.cucumber', name: 'cucumber-java8', version: '4.8.0', transitive: true)
testCompile(group: 'io.cucumber', name: 'cucumber-testng', version: '4.8.0', transitive: true)
}
my hope was that the transitive: true would then override the configuration level but it doesn't work.
I have also tried adding:
configurations {
all*.exclude group: 'io.cucumber', module: 'cucumber-java8'
}
but it then doesn't pull in this dependency at all
I'd prefer not to pull in all the dependencies for cucumber manually, and I'd rather not remove this configuration level transitive = false. Is it possible to do what I'm trying? Can I set the configuration just for compile dependencies? Or will I have to remove the configuration level setting and add transitive: false to every compile dependency?
Thanks for you help
I think you are looking for something like this:
configurations {
compile {
transitive false
}
testCompile {
transitive true
}
}
Related
I am using Gradle 6.4.1 and i am getting conflict for package com.jayway.jsonpath in org.apache.drill.exec:drill-jdbc-all:1.18.0 and spring-boot-starter-data-jpa.
So I want to exclude com.jayway.jsonpath package from drill-jdbc-all.jar
compile ('org.apache.drill.exec:drill-jdbc-all:1.18.0') {
exclude group: 'com.jayway.jsonpath'
exclude module: 'json-path'
}
compile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0'
Even tried this
configurations {
all {
compile.exclude module: 'com.jayway.jsonpath'
}
}
But still its showing
The class hierarchy was loaded from the following locations:
com.jayway.jsonpath.spi.mapper.JacksonMappingProvider: file:/Users/abc/.gradle/caches/modules-2/files-2.1/org.apache.drill.exec/drill-jdbc-all/1.18.0/6a0b608238f4a431684cd73d132d7467bc2c3967/drill-jdbc-all-1.18.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.jayway.jsonpath.spi.mapper.JacksonMappingProvider
Per the Excluding transitive dependencies section of the 6.4.1 docs, give this a try:
dependencies {
...
implementation('org.apache.drill.exec:drill-jdbc-all:1.18.0') {
exclude group: 'com.jayway.jsonpath', module: 'json-path'
}
...
}
I am using queryDsl to generate Q classes with Gradle. It used to work fine with Gradle 3.5, but on upgrading to Gradle 5.5.1, it is failing with duplicate class error.
My generateQueryDsl task works fine generating the classes under 'gensrc/' but on compileJava, the classes are generated again under 'build/generated/' which ends up giving duplicate class error.
dependencies {
api("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude group: "org.hibernate", module: "hibernate-entitymanager"
exclude group: "org.hibernate", module: "hibernate-core"
exclude group: "org.apache.tomcat", module: "tomcat-jdbc"
}
api("com.zaxxer:HikariCP:${hikaricpVersion}")
api("com.h2database:h2:1.4.193")
api("mysql:mysql-connector-java")
api("com.microsoft.sqlserver:sqljdbc42:6.0.8112")
api("org.springframework.data:spring-data-jpa")
api("org.springframework:spring-jdbc")
api("org.springframework:spring-orm")
api("org.eclipse.persistence:javax.persistence:${eclipseLinkPersistenceVersion}")
api("org.eclipse.persistence:eclipselink:${eclipseLinkVersion}")
api("org.eclipse.persistence:org.eclipse.persistence.jpa:${eclipseLinkVersion}")
api("com.mysema.querydsl:querydsl-sql:${queryDslVersion}")
api("com.mysema.querydsl:querydsl-jpa:${queryDslVersion}")
api("com.mysema.querydsl:querydsl-apt:${queryDslVersion}")
annotationProcessor('com.mysema.querydsl:querydsl-apt:3.7.4:jpa')
annotationProcessor("org.springframework.boot:spring-boot-starter-data-jpa")
}
task generateQueryDSL(type: JavaCompile, group: 'build) {
source = sourceSets.main.java
classpath = configurations.compileClasspath
options.annotationProcessorPath = configurations.annotationProcessor
destinationDir = file('gensrc/main/java')
}
compileJava {
dependsOn generateQueryDSL
}
error: duplicate class: com.persistence.domain.model.QOrganizationBasedModel
and likewise for all generated classes
When you use the annotationProcessor configuration, the default compileJava task adds the processor to the compiler, and it will generate classes in build/generated/sources/annotationProcessor/java/main.
In your case, you also declare an additional JavaCompile task, which you give the same annotationProcessor configuration, which will then generate the same classes again.
To solve this, I would simply delete generateQueryDSL task entirely as compileJava most likely does everything you need already. And if you like the generated sources in a different folder, you can do that through CompileOptions, but I would recommend having them under the build folder for most cases.
I have a strange problem. I have a project which creates a war file with some custom inclusions like images etc. So far it looks good. The only problem left is that gradle pulls in source jars/zips and javadoc jars/zip into my WEB-INF/lib/ folder of my war.
I thought it might be a problem with Idea but same results with the command line. I guess it has something to do with the dependency configuration?
I use compile and runtime scopes and my artifacts are resolved from Artifactory.
Can anyone point me to a direction where to fix that?
Update:
When i create a task:
task copyAllDependencies(type: Copy) {
from configurations.runtime
into 'allRuntime'
}
or
task copyAllDependencies(type: Copy) {
from configurations.compile
into 'allCompile'
}
I'll get the sources as well. So it seems that it has something to do with the compile/runtime configuration. They're pulling the sources and javadoc. But why?!
Dependencies are declared like this:
dependencies {
compile group: 'org.drools', name: 'drools-core', version: DROOLS_VERSION
compile group: 'org.drools', name: 'drools-compiler', version: DROOLS_VERSION
...
runtime group: 'net.sourceforge.barbecue', name: 'barbecue', version: '1.5-beta1', ext: 'jar'
...
testCompile group: 'org.fitnesse', name: 'fitnesse', version: '20130531'
...
}
Here's another attempt... a bit hacky but might work
configurations {
tempCompile
tempRuntime
tempTestCompile
}
dependencies {
tempCompile "org.drools:drools-core:${DROOLS_VERSION}"
tempRuntime "net.sourceforge.barbecue:barbecue:1.5-beta1#jar"
tempTestCompile "org.fitnesse:fitnesse:20130531"
...
compile configurations.tempCompile.asFileTree.matching {
exclude '**/*-sources.jar'
exclude '**/*-javadoc.jar'
}
runtime configurations.tempRuntime.asFileTree.matching {
exclude '**/*-sources.jar'
exclude '**/*-javadoc.jar'
}
testCompile configurations.tempTestCompile.asFileTree.matching {
exclude '**/*-sources.jar'
exclude '**/*-javadoc.jar'
}
}
As we discovered in the comments, your dependencies are bringing in javadoc and sources as transitive dependencies. You can possibly exclude these by
configurations.all { Configuration config ->
['com.group1', 'com.group2', ..., 'com.groupN'].each { groupId ->
config.exclude [group: groupId, classifier: 'javadoc']
config.exclude [group: groupId, classifier: 'sources']
}
}
Note: I'm not an ivy user so the selector (classifier: 'javadoc' etc) may need tweaking
This is for a Maven-to-Gradle build conversion on a large build. Think Rodan, Ghidora, Godzilla, etc. Yeah. That big.
Given a dependency that looks like this:
ext.jbossBom = [ ... ]// This is in the root project.
compile (rootProject.ext.jbossBom) //This is not in the root project
How can I exclude items from the above? I've tried variants of:
compile (rootProject.ext.jbossBom) {
exclude group: "some.group", module: "some.module"
}
jbossBom is a collection. Remove the element your want to eliminate:
compile (rootProject.ext.jbossBom.findAll{ !it.startsWith('some.group')})
To exclude a certain transitive dependency globally(irrespective of which dependency brings it in), you can do:
configurations {
compile.exclude group: 'commons-math3', module: 'commons-math3'
compile.exclude group: 'commons-pool2', module: 'commons-pool2'
}
To exclude a specific transitive dependency from each of the contents of jbossBom, you can do:
dependencies{
jbossBom.each{
compile (it){exclude group:'foo', module:'bar'}
}
}
I was wondering if it's possible to set a system property, for a Java application, using Gradle?
I tried using gradle.properties file and defining a property as
systemProp.name = my name
but then when I try to get that property from a Java application using
System.getProperty("name")
that property is not found.
build.gradle and gradle.properties are in root folder of the project.
This is what my build.gradle looks like:
apply plugin: 'war'
apply plugin: 'appengine'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.8.6'
}
}
appengine {
httpPort = 8081
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile group: 'com.google.inject.extensions', name: 'guice-servlet', version: '3.0'
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.2.0.Final'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'
compile 'com.google.protobuf:protobuf-java:2.5.0'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.8.6'
compile 'com.google.template:soy:2012-12-21'
compile 'org.json:json:20090211'
}
And this is what my build.properties look like:
systemProp.firstName=Marko
systemProp.lastName=Vuksanovic
This is part of an AppEngine application and I run it using the following command:
gradle appengineRun
This is how I do it, setting props for Selenide test framework:
test {
systemProperty "browser", "chrome"
systemProperty "webdriver.chrome.driver", "$projectDir/drivers/chromedriver"
}
I just stumbled on this for use with the gradle application plugin. Add to the run task. Works great:
run {
systemProperties['MYPROP'] = '/my/prop/value'
}
This is what worked for me (using Kotlin DSL):
tasks.withType<JavaExec> {
systemProperty("key", "value")
}
The system property set in gradle.properties will be available only in JVM where Gradle is running.
From gradle-appengine-plugin documentation:
appengineRun: Starts a local development server running your project
code.
jvmFlags: The JVM flags to pass on to the local development server.
If you need your system properties to be available in app engine, which is separate JVM, you should use jvmFlags property.
Explicitly:
appengine {
jvmFlags = ['-DfirstName=Marko', '-DlastName=Vuksanovic']
}
With gradle.properties:
appengine {
jvmFlags = ['-DfirstName=$firstName', '-DlastName=$lastName']
}