Process a subset of my dependencies in Gradle - gradle

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

Related

How to share dependencies between sibling multi-projects in gradle?

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

Maven Project in IntelliJ, include Gradle Plugin

I'm new to IntelliJ and Gradle
I've got a Maven Project with a lot of dependencies which works on it's own.
Now I should use the libraries from that Project and create a Plugin for IntelliJ in Gradle.
I tried various ways to add the dependencies in the IntelliJ Module Settings, which allowed me to use the needed classes to write my code and build it. However, when I tried to start the plugin, it couldn't find the classes anymore.
I think I need to specify these in the build.gradle but I don't understand exactly how, as all the ways I tried didn't worked.
build.gradle:
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.6.5'
}
group 'com.ast.devmate.intellij'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
**compile 'com.ast.devmate.intellij:root:1.0.0-SNAPSHOT'**
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2019.1'
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}
gets me this:
Could not find com.ast.devmate.intellij:root:1.0.0-SNAPSHOT.
without the line marked with ** I got a lot of
error: package foo does not exist
import foo;
It looks like you're trying to access a custom library using Gradle. You will probably need to use a file dependency: How to add local .jar file dependency to build.gradle file?

gradle dependency with classifier

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

Gradle does not download complete dependencies

Im trying to download and build spring-data-hadoop 2.4.0.RELEASE using the following decleration in my dependencies.gradle:
dependencies {
...
// compile('org.springframework.data:spring-data_hadoop:2.4.0.RELEASE')
compile group: 'org.springframework.data', name: 'spring-data-hadoop', version: '2.4.0.RELEASE'
...
}
Refreshing gradle now results in downloading the newly added dependency BUT the data is not consistend. I got the following external dependencies after the download:
I thought everything is fine now... but I am wrong. Lets open up one of those and look depper into the packages:
If you compare the content of org.springframework.data.hadoop.config with the official API you will notice, that in this package, there should be much more content. The annotations package for example.
How can it be that gradle is not downloading the complete source?
There is a separate spring-data-hadoop-config with the description "Spring for Apache Hadoop Annotation Configuration", so that's probably where annotations would be.
You are pulling the main jar that should pull the transitive artifacts as well.
the org.springframework.data.hadoop.config.annotation is included inside
compile group: 'org.springframework.data', name: 'spring-data-hadoop-config', version: '2.4.0.RELEASE'

could not resolve all dependencies for configuration ':compile'

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.

Resources