I am using gradle version 4.6:
in dependencies I add this:
testCompile "com.kuku:kuku:1.0:tests"
also tried this and same:
testCompile group: "com.kuku", name: "kuku", version: "1.0", classifier: "tests"
then gradle throw error:
Could not resolve all files for configuration ':testCompileClasspath'.
Could not find kuku-tests.jar (project :serializer_v9).
what I am doing wrong? needless to say I see the kuku tests jar in the build directory
So I found that the problem is Gradle includeBuild does not support yet publication that does not default: here
So the only way is to create separate jar with the test classes
Related
My project uses Gradle's multi-project system. Most of my projects include the "lemur-common" library like this
dependencies {
compile project(":lemur-common")
}
"lemur-common" also has a unit test directory, which has a somewhat complicated dependency statement.
dependencies {
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.3.9.RELEASE'
testCompile group: 'org.mockito', name: 'mockito-inline', version: '3.5.6'
constraints {
implementation('org.mockito:mockito-core:3.5.6') {
because 'Fixes illegal reflective access warning'
}
}
}
Now, all of my other projects need to have this same line, since they're all using spring-boot-starter-test. I've done quite a bit of fiddling, trying to express something like "project-a's testCompile should have the same dependencies as lemur-common" but I haven't gotten it to work.
Is it possible to express this in Gradle? Does anyone know how?
You'll want to create a custom Gradle plugin.
As a sibling of all your project dirs, create a buildSrc directory, which itself will have a Gradle file (it needs to be built like everything else). Make gradle file under src, which will be your plugin. Put all of the shared gradle code (the dependencies block you posted) in that file. For example:
- buildSrc
|── build.gradle
|── settings.gradle
|── src
|── main
|── groovy
|── unit-test-dependencies.gradle
Then, in the build.gradle of lemur-common, projectA, and etc. add this line
plugins {
id 'unit-test-dependencies'
}
That should do it. Gradle's documentation for this feature is here: https://docs.gradle.org/current/samples/sample_convention_plugins.html
In build.gradle we specify the dependencies as
compile group: 'org.apache.pig', name: 'pigunit', version: '0.11.0-cdh4.5.0', transitive: true
Running gradle cleanEclipse eclipse sets up the projects(adds the jar to classpath)
However there are only maven dependencies available for some APIs
(I am trying to run jersey 2.x examples bundle from https://jersey.java.net/download.html and it provides only pom.xml)
EDIT:
I know i can specify
compile group: 'groupId', name: 'artifactId', version: 'version' gradle but doing it manually for all dependencies or writing a program to do so should not be natural gradle way.
Gradle provides a maven plugin http://gradle.org/docs/current/userguide/maven_plugin.html.I haven't tried it out but it should be able to do it
Gradle supports Maven dependencies. Just specify the dependencies in the same way as your example:
compile group: 'groupId', name: 'artifactId', version: 'version'
To lookup the the artifact coordinates, you can use sites like http://search.maven.org
The only thing you have to make sure is to include either your internal Maven repository (if you are in a company which has one) or Maven Central:
repositories {
mavenCentral()
}
or
repositories {
maven {
url "http://repo.mycompany.com/maven2"
}
}
I have a multiple project Gradle build in which a submodule need to reference some helper classes defined in the parent module test configuration.
In the submodule I've added the following definition:
dependencies {
compile project(path: ':')
testCompile project(path: ':', configuration: 'testCompile')
}
However the submodule test compilation faila because it is unable to resolve classes defined in the parent testCompile configuration.
How to reference the parent test configuration in a submodule in a Gradle build ?
compile project(project.parent.path)
testCompile project(project.parent.path, configuration: 'testCompile')
If you need configuration, you can find it like this:
project.parent.configurations.testCompile
UPDATE
Solution:
testCompile files(project.parent.sourceSets.test.output)
To study Gradle I am using the book Gradle in action.
There was an example of dependency definition.
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
But when I do in console gradle build I've got an error
What is the problem? My whole .gradle file looks like this
apply plugin: 'java'
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
You did not tell Gradle where to find commons-lang3 library. Easy fix is to add the following to your build script:
repositories {
mavenCentral()
}
Of course you can find this piece of information in documentation - http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html#N10608
I was facing this same issue. I fixed it by using local gradle distribution instead of the default gradle wrapper. This is how it goes, make sure that you have Gradle installed and setup(PATH variable).
Open IntelliJ. Goto File->setting->Build, Exec, Deployment->Build tools->Gradle and use local gradle distribution and add your Gradle Home. Apply changes and try to run it now.
I have a simple project where I'd like to unjar a subset of my dependencies and pack them into the output jar.
I have the two configurations:
configurations {
embed
all
}
dependencies {
embed group: 'commons-collections', name: 'commons-collections', version: '3.2'
...
all embed
all group: 'something-not-embeddable', name: 'dontembed'
compile all
}
According to http://www.gradle.org/docs/current/userguide/dependency_management.html 50.5 Working with Dependencies section's example it should work.
In a later section of my build, I want to unjar the embed jars and use them as source for jar.
My problem is that the gradle output says:
> Could not find method all() for arguments [configuration ':embed'] on root project 'myproject'.
Can you tell me why my approach is not working and how could I fix it?
Lol, looks like I chose a bad configuration name, works with alldeps instead of all