Below is my gradle build script:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}
apply plugin: 'spring-boot'
apply plugin: 'base'
task wrapper(type: Wrapper) {
gradleVersion = '2.12'
}
repositories {
ivy {
url 'my.url'
}
}
dependencies {
archives group: 'my.group', name: 'artifact.name', version: '16.06.29.5144', configuration: 'dist'
}
In it I try to add one dependency to archives configuration. This is dependency published into Ivy repo and it has several configuration, among them a dist configuration. But it does not have default configuration.
Now, if I run gradlew dependencies I get the following error:
Execution failed for task ':dependencies'.
Could not resolve all dependencies for configuration 'detachedConfiguration4'.
> Module version :gtest:unspecified, configuration 'detachedConfiguration4' declares a dependency on configuration 'default' which is not declared in the module descriptor for my.group:artifact.name:16.06.29.5144
When I remove spring-boot plugin, then error disappears and I see expected output:
archives - Configuration for archive artifacts.
\--- my.group:artifact.name:16.06.29.5144
Any ideas why spring-boot plugin breaks dependency on custom configuration?
Your custom artifact looks to be another trigger of a bug/limitation in Gradle. The failure's occurring due to some logic in the dependency management plugin that Spring Boot's plugin uses that, among other things, ensures that any exclusions declared in dependencies' poms are applied as intended.
You can work around the problem, at the cost of perhaps having to declare some additional exclusions, by telling the dependency management plugin not to apply Maven exclusion semantics:
dependencyManagement {
applyMavenExclusions false
}
Related
I have three module as shown below
The fete-bird-apigateway depend on common and fete-bird-product depend on both fete-bird-apigateway and common
In the fete-bird-product settings.gradle I have included the code below
rootProject.name = "fete-bird-product"
include 'fete-bird-apigateway' , 'common'
and in the build.gradle of project
dependencies {
implementation project(':common')
}
Error
Caused by: org.gradle.internal.component.NoMatchingConfigurationSelectionException: No matching configuration of project :common was found.
I don't want to create a multi-module build project describe here https://docs.gradle.org/current/userguide/multi_project_builds.html. Each project should build individually and dependent modules should load while building.
How can I achieve this?
Well I found that I had the wrong concept for different module projects.
Assuming all modules are part of the same multi-module build then in fete-bird-apigateway.gradle and service\build.gradle you add:
plugins {
id 'java'
id 'maven-publish'
}
dependencies {
implementation project(':common')
}
However if common, fete-bird-apigateway and service are separate projects and don't share the same root build.gradle you have to publish the common module into a shared repository and use it like any regular dependency. Easiest to do with Maven Local repository.
To publish to the local maven
In fete-bird-apigateway.gradle
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.gradle.sample'
artifactId = 'library'
version = '1.1'
from components.java
}
}
}
Reference - https://docs.gradle.org/current/userguide/declaring_repositories.html
https://docs.gradle.org/current/userguide/publishing_maven.html#gsc.tab=0
In the dependent project add the dependency as regular
repositories {
mavenLocal()
}
implementation("fete.bird:fete-bird-apigateway:0.1")
We need to run the task or gradle command for publish. I am using Intellj so did with below task
We can run the gradle command gradle publishToMavenLocal
One can run gradlew dependencies to learn about dependencies of module tasks. It there a way to find transitive dependencies of buildscript dependencies?
Example:
classpath 'com.android.tools.build:gradle:1.0.0' depends directly on:
com.android.tools.build builder
com.android.tools.lint lint
net.sf.proguard proguard-gradle
tools.base project-test-lib
As can be seen on MVNRepository. But this artifacts have their own dependencies. Is there and way to find those out without manually traversing whole dependency tree?
As a clarification, the classpath I'm talking about is defined by:
buildscript {
repositories {}
dependencies { .... }
}
Beginning with Gradle 2.10 you can now get information on buildscript dependencies via
gradle buildEnvironment
With older versions you'll have to explicitly define a task of type DependencyReportTask configured with your build script configuration.
task buildscriptDependencies(type: DependencyReportTask) {
configurations = [buildscript.configurations.classpath]
}
I think you're looking for Gradle's DependencyInsightReportTask
You can use this command:
gradle dependencyInsight --dependency gradle
There is awesome tutorial by Udacity, Gradle for Android, but you can watch this video for more explanation.
I've already solved this but i'm still curious as to why gradle behaves this way.
In my gradle project i have 2 gradle projects, one named app that is configured with the ear plugin and one named core that is deployed in the lib folder of the ear
I was getting the following error when trying to build my gradle project:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':app:earlib'.
> Could not find org.slf4j:slf4j-api:1.7.5.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find commons-io:commons-io:2.4.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find org.slf4j:slf4j-log4j12:1.7.5.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find log4j:log4j:1.2.17.
Required by:
saturn:app:unspecified > saturn:core:unspecified
My app build.gradle file is:
apply plugin: 'ear'
dependencies {
earlib project(":core")
}
and my core build.gradle is:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
runtime 'org.slf4j:slf4j-log4j12:1.7.5'
runtime 'log4j:log4j:1.2.17'
testCompile 'junit:junit:4.11'
}
Temporary Solution:
I was able to resolve the issue by adding the mavenCentral repository to my app build.gradle like so:
apply plugin: 'ear'
repositories {
mavenCentral()
}
dependencies {
earlib project(':core')
}
HOWEVER I'm still curious as to why the depending project needs to know what repository the core project resolves it's dependencies from. this document on dependency management doesn't seem to have a very good explanation.
When resolving a configuration, Gradle (only) uses the repositories declared in the same project as the configuration. Hence when resolving the ear project's earlib configuration, only the ear project's repositories are taken into account. That's one reason why it's common to declare all repositories under subprojects in the root build script.
I have an issue with how gradle resolves my dependencies.
I have four repositories that I need to investigate for different jars, five counting Maven central. Thus my repo statment in gradle.build looks like this:
repositories {
maven {
url 'urltoRepoA'
artifactUrls mavenLocal()
}
maven {
url 'urltoRepoB'
artifactUrls mavenLocal()
}
maven {
url 'urltoRepoC'
artifactUrls mavenLocal()
}
maven {
url 'urltoRepoD'
artifactUrls mavenLocal()
}
mavenCentral()
}
What I want to acheive:
Look for dependencies both in the remote repositories and the local maven repository.
But I get this error below, that is a jar that should be resolved from repoA (repoA is a mirror of maven central, and I have verified that this jar can be found there)
[16:43:10][Step 1/3] > Could not resolve all dependencies for configuration ':runtime'.
[16:43:10][Step 1/3] > Artifact 'junit:junit:4.11#jar' not found.
According to what I've read in gradles manual is that it tries to resolve all the dependencies from the same repo. Is that what I'm running in to here? Or have I failed to configure gradle properly?
I suspect there is something wrong elsewhere in your gradle configuration. I think you are misunderstanding how gradle resolves artifacts.
According to the gradle docs (see section 8.5)
A project can have multiple repositories. Gradle will look for a
dependency in each repository in the order they are specified,
stopping at the first repository that contains the requested module.
In fact, it's rather common to have multiple repositories in a gradle script.
I am using Spring 3.2 with Java based configuration and have some problems with my unit tests (JUnit 4.8.1). So this is a test runner:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(classes={TestConfig.class})
public class ManualTest
{
#Autowired
...
Howeever, I am receiving this error:
Caused by: java.lang.IllegalStateException: CGLIB is required to process #Configuration classes. Either add CGLIB to the classpath or remove the following #Configuration bean definitions: [testConfig]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:327)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:222)
As the Spring blog states, Spring 3.2 is inlining CGLIB 3. So why do I receive this error?
I am using Gradle 1.3 as build management tool and STS as IDE. When calling gradle eclipse gradle pulls in the dependencies twice: one time as plain jar and one time as library:
First as plain jar:
and than as library:
In the plain jar section I had still Spring 3.1 configured, while in the library section there was Spring 3.2. So I removed the plain jars and everything was working.
This is my project build.gradle
configurations
{
driver
}
dependencies
{
driver 'com.oracle:ojdbc6:11.2.0'
compile "org.springframework:spring-jdbc:$springVersion"
testCompile 'com.oracle:ojdbc6:11.2.0'
testCompile "org.springframework:spring-test:$springVersion"
testCompile "commons-dbcp:commons-dbcp:$dbcpVersion"
testCompile "junit:junit:$junitVersion"
testCompile "org.slf4j:slf4j-log4j12:$slf4jVersion"
}
sourceSets
{
main
{
java
{
srcDirs 'src/main/java', "$buildDir/generated-sources/"
}
}
}
And the build.gradle from the master project
configure(allprojects)
{
ext.dbcpVersion = '1.4'
ext.springVersion = '3.2.0.RELEASE'
ext.junitVersion = '4.8.1'
ext.slf4jVersion = '1.7.2'
}
subprojects
{
// Artifact settings
group = 'xxx'
version = '1.0-SNAPSHOT'
// Standard plugins
apply plugin: 'java'
apply plugin: 'eclipse'
// Repositories
repositories
{
mavenLocal()
maven
{
url "http://repo.springsource.org/release"
}
mavenCentral()
}
// Standard dependencies
dependencies
{
}
}
I deleted all Eclipse projects and settings and all Gradle temporary files. Then I tried to import the project in Eclipse (Import Gradle project..). This failed with an exception. Then I deleted the Gradle settings within the Eclipse project and after that the import worked.
So I will not use gradle eclipse with version 1.3.
Also the additional source set path did not make its way into the Eclipse project as source path.
I had the same issue. Just add this dependency to your pom.xml file:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
And your unit tests and runtime code should work properly without cglib errors.