Gradle won't build because it can't resolve dependencies of dependencies. For example, I have a project MyStarterWeb which has a dependency on spring-boot-starter-web:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:3.0.2'
}
I have a second project, MyFirstEndPoint, that extends/uses/is dependent upon MyStarterWeb:
dependencies {
implementation 'group: 'com.mygroup', name: 'MyStarterWeb', version: '0.0.1-SNAPSHOT'
}
After reading the Gradle docs (which are contradicting, confusing and of little value), I understood that Gradle would resolve all the dependencies for the MyFirstEndPoint project without having to list the spring dependencies listed in MyStarterWeb. But, this is not the case:
error: package org.springframework.boot does not exist
import org.springframework.boot.SpringApplication;
Any help/explanation/guidance/clarification on the poor Gradle docs is greatly appreciated. If there's an RTFM link that I missed, please share
For anyone who runs into this issue with Gradle not resolving transitive dependencies (using Gradle 6.0+) for a self-published artifact/library, the solution was to change the MyStarterWeb project to use the java-library plugin:
plugins {
id 'java'
id 'java-library'
id 'org.springframework.boot' version '3.0.2'
id 'io.spring.dependency-management' version '1.1.0'
}
and then to change the dependencies in MyStarterWeb to use the api configuration instead of implementation configuration.
dependencies {
api 'javax.servlet:javax.servlet-api:4.0.1'
api 'org.springframework.boot:spring-boot-starter-web:3.0.2'
}
That allowed the MyFirstEndPoint project to resolve all transitive dependencies and only have to specify the MyStarterWeb dependency
dependencies {
implementation group:'bla', name: 'MyStarterWeb', version: '0.0.1-SNAPSHOT'
}
Related
jdk 1.8.
Gradle 7.3
In my java project I want to write unit test by Kotlin. So I try this:
in build.gradle:
plugins {
id 'application'
id "com.nocwriter.runsql" version "1.0.3"
id 'idea'
id "io.spring.dependency-management" version "1.0.11.RELEASE"
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
}
apply plugin: "io.spring.dependency-management"
dependencies {
// The dependencies in the BOM will be dependency constraints in our build, but the versions in the BOM are forced for used dependencies.
implementation enforcedPlatform('org.springframework.boot:spring-boot-dependencies:2.7.2')
// Use dependency defined in BOM.
// Version is not needed, because the version defined in the BOM is a dependency constraint that is used.
implementation 'org.xerial:sqlite-jdbc'
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
testImplementation(
'org.assertj:assertj-core',
'org.junit.jupiter:junit-jupiter-api'
)
testRuntime('org.junit.jupiter:junit-jupiter-engine')
// This version will be overridden by the one found in the BOM
implementation 'log4j:log4j:1.2.17'
implementation 'com.toedter:jcalendar:1.4'
}
Usage:
./gradlew build
But I get error in this line:
testRuntime('org.junit.jupiter:junit-jupiter-engine')
Error:
What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method testRuntime() for arguments [org.junit.jupiter:junit-jupiter-engine] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Change to
testImplementation "org.junit.jupiter:junit-jupiter-engine"
Converting a SpringBoot Maven Build to Gradle 6.5, Maven works fine (pre conversion) Gradle BootJar (or even just build) fails with:
[Fatal Error] jboss-parent-12.pom:811:1: Content is not allowed in trailing section.
Why is jboss parent 12 being referenced here? this is an ancient pom, and using --scan does not reveal jboss at all. (--scan dependency list below)
com.fasterxml.jackson.core:jackson-annotations:2.11.0
com.fasterxml.jackson.core:jackson-core:2.11.0
com.fasterxml.jackson.core:jackson-databind:2.11.0
com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.0
com.gradle:gradle-enterprise-gradle-plugin:3.3.3
commons-codec:commons-codec:1.14
io.freefair.gradle:lombok-plugin:5.1.0
io.freefair.lombok:io.freefair.lombok.gradle.plugin:5.1.0
io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE
net.java.dev.jna:jna-platform:5.5.0
net.java.dev.jna:jna:5.5.0
org.apache.commons:commons-compress:1.19
org.apache.httpcomponents:httpclient:4.5.12
org.apache.httpcomponents:httpcore:4.4.13
org.springframework.boot:org.springframework.boot.gradle.plugin:2.3.1.RELEASE
org.springframework.boot:spring-boot-buildpack-platform:2.3.1.RELEASE
org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE
org.springframework.boot:spring-boot-gradle-plugin:2.3.1.RELEASE
org.springframework.boot:spring-boot-loader-tools:2.3.1.RELEASE
org.springframework.boot:spring-boot-parent:2.3.1.RELEASE
org.springframework:spring-core:5.2.7.RELEASE
org.springframework:spring-jcl:5.2.7.RELEASE
org.testcontainers:testcontainers-bom:1.14.2
Alternatively, is there a way to ignore it? BootJar does not generate a jar even with
plugins {
id 'java'
id 'application'
id 'io.freefair.lombok' version '5.1.0'
id 'org.springframework.boot' version '2.3.1.RELEASE'
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
jar {
enabled = true
}
application {
mainClass = 'my.main.class.MyApplication'
}
Not an expert in build tools but you can proceed with the below steps :
gradle clean build
or Can explicitly exclude the dependency :
configurations.all {
exclude group: "org.jboss", module: "jboss-parent"
}
I hope this will help you.
I'm working on some legacy code with the following versions:
Gradle 4.10.2
Spring Boot 1.5.16.RELEASE
I was expecting that any dependencies I specify with the implementation dependency configuration would be placed in the Spring Boot fat jar when I execute the assemble task. However they are not.
I've resorted to using the deprecated compile dependency configuration for now, but I'm confused as to why implementation doesn't work.
Simplified build.gradle is as follows:
plugins {
id 'java'
id "org.springframework.boot" version "1.5.16.RELEASE"
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.commons:commons-lang3:3.10'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
In the example above, I would have expected commons-lang3-3.10.jar to be put inside the fat jar when I execute the assemble Gradle task. It does not!
The most likely explanation is that this version of the Spring boot plugin did not support the reworked configurations of the Gradle java plugins.
I am new to both Gradle and JavaFX. I have added the JavaFX plugin to my build.gradle following this and this. However, my main class Library.java is not able to detect the Application class of JavaFX when I am trying to extend it.
build.gradle
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
jar {
manifest {
attributes 'Main-Class': 'Chess.Library'
}
}
mainClassName = 'Chess.Library'
Screenshot of Library Class
There's no Application from javafx package at all. What am I missing here?
I am using Spring Tool Suite 4.0 as my IDE with Buildship Gradle plugin if that's of any help. I am also running on Oracle Java 13
Edit 1:
I have added the changes suggested and this is how my build.gradle now looks
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
jar {
manifest {
attributes 'Main-Class': 'Chess.Library'
}
}
javafx {
version = "13"
modules = [ 'javafx.controls' ]
}
mainClassName = 'Chess.Library'
But the problem is still there
I also checked my Project and External Dependencies, there are all the libraries except for javafx
I fixed the issue myself although not sure what was causing it, but my project's buildpath had an unbounded Java 13. Fixing that and restarting the IDE took care of it
I would like to use the most recent version of Dropwizard, unfortunately I cannot, because Gradle is unable to resolve it.
Here is my build.gradle file:
group 'com.gaboratorium'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
ext {
dropwizardVersion = '1.2.0'
}
repositories {
mavenCentral()
}
dependencies {
// Application
implementation "io.dropwizard:dropwizard-core:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-db:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-jdbi:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-auth:${dropwizardVersion}"
implementation "io.dropwizard:dropwizard-migrations:${dropwizardVersion}"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Things I have tried:
Using jcenter repository instead
IntelliJ > Invalidate caches / Restart
Using an older version instead; the only one I could make work was 0.8.2
Did anyone experience something similar?
As it turned out my issue was that proxying was set up in my IntelliJ thanks to a previous project, which I was not aware of. However during my research for the problem I have found some relevant answers to this question, which I am going to place here for future reference:
IntellijIDEA not recognizing classes specified in Maven dependencies
Maven - can't download fasterxml.jackson
Gradle build doesn't download dependencies