Gradle dependency of modules in intellij - gradle

I have 2 modules in an intellij project..One intellij plugin module and another one is an gradle module.
I need to call a class of the plugin module from the gradle module..I did add dependency of module by following this path: Project structure->module->Module dependency.But it is not resolved.
I have also added the below code in:
settings.gradle
include ':Change',':module'
build.gradle
dependencies{
compile project (:Change)
}
Here 'Change' is the name of the intellij plugin module.
Every time I try to build the gradle it throws below error:
Could not determine the dependencies of task ':distTar'.
Could not resolve all task dependencies for configuration ':runtimeClasspath'.
> Could not resolve project :ChangeImpactAnalysis.
Required by:
project :
> Unable to find a matching configuration of project :ChangeImpactAnalysis: None of the consumable configurations have attributes.
Please help

Related

subprojects dependencies failure with Gradle

I'm struggling with Gradle and the build configuration of the following project structure (pretty simple...):
/projA
/projB
/projC
projC using classes from projB.
In projA/settings.gradle:
include 'projB'
include 'projC'
In projC/build.gradle:
dependencies{
compile project(':projB')
}
In IntelliJ I have no problem of dependency resolution, but when I'm running a ./gradlew build in projA, I'm facing a compilation error:
ClassC: Unresolved reference: ClassB
(where ClassC is the class of projC which is failing on the use of ClassB which is a class from projB, obviously...)
Notice that the code is in Kotlin language, that I do not have any problem to run the app in IntelliJ (spring boot run), but any build with Gradle give me an error (both in Intellij and command line).
What am I missing?
Regards,
Adrien
It's a common Gradle idiom to have an additional top level directory for your rootProject. That's a special project that's the parent to all other projects in your build, in a multi-project build.
That's where your settings.gradle file goes:
include ':projA:projB'
include ':projA:projC'
Then, I'd recommend having projA as a subdirectory of your rootProject, so your hierarchy would look as follows:
/myProject
settings.gradle
/projA
build.gradle
/projB
build.gradle
/projC
build.gradle
Also, in projC/build.gradle, you'll want instead:
dependencies {
compile project(':projA:projB')
}
That should do it.

Gradle: Dependency insight report cannot be generated because the input configuration was not specified

I'm trying to resolve dependency conflict in my gradle applicaiton. My top-level build.gradle is:
archivesBaseName = 'message-sender-rest'
apply plugin: 'paas-publish'
dependencies {
compile(project(':message-sender-api'))
compile(libraries.springBoot)
compile(libraries.loggingRuntime)
compile(libraries.integration)
compile(libraries.serviceFrameworkServer)
compile(libraries.serviceFrameworkApp)
compile(libraries.serviceFrameworkSpringIntegration)
testCompile(libraries.testing)
testCompile(libraries.springTest)
testCompile(libraries.activeMqBroker)
}
When I try to run gradle dependencyInsight --configuration compile, I get the following error:
* What went wrong:
Configuration with name 'compile' not found.
There is a whole bunch of lower level gradle files, but I guess that should just work using the top-level one, isn't it?
When i just try gradle dependencies, it returns pretty much nothing:
gradle dependencies
dockerBuild tag: dev.docker.orbitbenefits.capita/orbit/message-sender-rest:bOD-9656-ConfigServer-n0
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
No configurations
BUILD SUCCESSFUL
Any idea what I may be missing?
I was not specifying the module I wanted to inspect:
The project had a sub-project (module message-sender-server). Specifying the module name actually worked:
gradlew message-sender-server:dependencyInsight --dependency webmvc

Gradle fails to detect flat dependency

I have a multi-project Gradle build (Gradle 4.4).
And I encountered the following issue.
Let's say I have proj1 project with the following build.gradle:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile name: 'lombok-edge'
}
proj1 has libs folder with lombok-edge.jar. Project is built successfully.
And I have proj2 that imports proj1:
dependencies {
compile project(':proj1')
}
When I try to build the whole project proj1 is build but Gradle fails to build proj2 with an error:
What went wrong:
Could not resolve all files for configuration ':proj2:compileClasspath'.
Could not find :lombok-edge:.
Required by:
project :proj2 > project :proj1
Please advise.
Well, Gradle supports transitive dependencies, but the way how to get a dependency (and therefor any repository information) is not transitive. Gradle (like Maven) does not care where a dependency comes from, as long as it matches a given signature (group, id, version).
In your example, project 1 defines a Maven dependency and can resolve it via the given flatDir repository. Project 2 has dependencies on both project 1 (which is resolved by Gradle) and the transitive Maven dependency. It's the responsibility of project 2 to resolve this dependency and it will check any defined repository, but cannot find it, because the local repository is unkown. This is the reason why the build fails.
If the two projects are related, as they should be if they are both parts of a multi-project build, you should define the local repository in a top-level build.gradle file and a subprojects closure.

How to stop buildSrc from automatically applying groovy-all jar as a dependency?

I have a Gradle project set up, which has a buildSrc module inside of it. Inside buildSrc, in build.gradle, I have the following:
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.12'
...
}
When trying to do a build for the project, I receive the following error message:
2:07:13 PM: Executing external task 'build --stacktrace'...
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildSrc:compileGroovy'.
> java.lang.ExceptionInInitializerError (no error message)
In the stacktrace, I see the following error:
Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.4.11 and you are trying to load version 2.4.12
... 15 more
So, when I look at the project structure, I see that the groovy-all-2.4.11.jar is automatically being loaded into the buildSrc module.
If I remove the compile dependency for Groovy in build.gradle, it will work, but is there any way to force the module to use the version of Groovy that I want?
Gradle always applies the default build script to buildSrc project. This script contains following line:
compile localGroovy()
that is how groovy-all-2.4.11 gets in. To override this behaviour, try setting the resolutionStrategy, e.g.:
configurations.compile {
resolutionStrategy {
force 'org.codehaus.groovy:groovy-all:2.4.12'
}
}
but more importantly think, why would you want to build against a groovy version that differs from one available in your plugin's runtime...

Grails 3.2.9 custom plugin dependencies

Is it possible to make one custom plugin in Grails 3 dependent on another custom plugin? Here's my project structure:
grails3-home
myApp
customPlugin1
build.gradle
settings.gradle
customPlugin2 ...
I would like to make customPlugin1 dependent on customPlugin2. Everything I've read says this possible with multi-project builds between apps and plugins in Grails 3. And I'm able to declare both plugins as dependencies in myApp with no issues. However, I have not been successful in getting this to work between the two plugins.
I have added the following line to customPlugin1 > settings.gradle
include "customPlugin2"
And to customPlugin1 > build.gradle
grails {
plugins {
compile project(':customPlugin2')
}
}
However when I try to build customPlugin1, I get the following error:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'customPlugin1'.
Could not resolve all dependencies for configuration ':runtime'.
Project : declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :customPlugin2.
Is anyone aware if what I'm trying to do is possible, and if so, what I might be missing?
Update:
If I change my configuration to
include "../customPlugin2"
and
grails {
plugins {
compile project(':../customPlugin2')
}
}
the plugin builds successfully, but I am no longer able to import domains classes from customPlugin2 into customPlugin1 domains classes
You should do the include in the root settings.gradle
include 'myApp', 'customPlugin1', 'customPlugin2'
Then in plugin 1:
grails {
plugins {
compile project(':customPlugin2')
}
}
Note that this simply defines a dependency. If you need plugin 2 to load before or after plugin 1 you need to define that as well in the plugin descriptor.

Resources