Cannot change dependencies of configuration ':implementation' after it has been included in dependency resolution - spring

I have got a very basic build.gradle file.
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
bootJar{
mainClassName = "$mainClassName";
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
I get the following error when bootJar task is placed before dependencies block. When placed after the dependencies block i don't get an error.
What went wrong:
A problem occurred evaluating root project 'sample-project-spring-boot'.
Cannot change dependencies of configuration ':implementation' after it has been included in dependency resolution.

Related

Build failed Spring Boot Plugin was not found

I download a repo 'gs-handling-form-submission' from spring.io and now I'm trying to build: gradle build
Following Error has being triggered
* Where:
Build file 'C:\Users\Username\Desktop\gs-handling-form-submission\complete\build.gradle' line: 11
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.4.2'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.4.2')
Searched in the following repositories:
Gradle Central Plugin Repository
I already added a repo url, changed spring.boot version, added buildscript.repositories() at the first line, even doing that, I can't get to compile.
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
mavenCentral()
maven {
url: "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
Fixing the build.gradle, removing : url, was possible to build
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}

Gradle Checkstyle plugin compatibility with google checkstyle

I've installed the google-java-format plugin and placed the following checkstyle in config/checkstyle/checkstyle.xml:
https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml
My build.gradle looks like this:
plugins {
id 'org.springframework.boot' version '2.5.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'checkstyle'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
So, when I run the task checkstyleMain, The following error message appears:
Document root element "code_scheme", must match DOCTYPE root "null".
Can anybody help?

Cannot resolve external dependency org.springframework.boot:spring-boot-dependencies:2.4.1 because no repositories are defined

I created a multimodule spring boot, every module use spring.
My nvoice build.gradle
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'org.springframework.boot' version '2.4.1'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
allprojects {
group = 'com.torenda'
sourceCompatibility = '11'
}
subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
repositories {
mavenCentral()
}
}
bootJar {
enabled = false
}
settings.gradle of nvoice
rootProject.name = 'nvoice'
include ':invoice'
include ':payment'
build.gradle of my invoice module
description = 'invoice'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'io.r2dbc:r2dbc-postgresql'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
bootJar {
enabled = true
}
When I try to build the app I get
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRunMainClassName'.
Could not resolve all dependencies for configuration ':detachedConfiguration1'.
Cannot resolve external dependency org.springframework.boot:spring-boot-dependencies:2.4.1 because no repositories are defined.
Required by:
project :
Like you can see, repositories is definined in the main gradle file and i added it in the subprojects section too
It works if you move repositories under allprojects and remove buildscript:
plugins {
id 'org.springframework.boot' version '2.4.1'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
allprojects {
group = 'com.torenda'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
}
bootJar {
enabled = false
}

Unable to build SpringBootProject from terminal i.e command line

Could not resolve all files for configuration ':classpath'.
Could not resolve org.springframework.boot:spring-boot-gradle-plugin:2.3.0.RELEASE.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:2.3.0.RELEASE
Could not resolve org.springframework.boot:spring-boot-gradle-plugin:2.3.0.RELEASE.
Could not parse POM https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/2.3.0.RELEASE/spring-boot-gradle-plugin-2.3.0.RELEASE.pom
Unable to resolve version for dependency 'org.apache.commons:commons-compress:jar'
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.learn'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.oracle.ojdbc:ojdbc8'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}

Trying to modularize Gradle SpringBoot Project but getting "Error: cannot find symbol" when trying to build?

I had a working single-module Java project I am trying to break up into two modules: a library, and an application module. I pulled out the Java libraries from the top level build.gradle and stuffed them in the library build.gradle, and kept the SpringBoot/Docker/MySQL related dependencies in the application build file. Running ./gradlew build causes errors due to "cannot find symbol" errors on the lombok stuff in the App.
I added a top level settings.gradle (code below), pulled out all the Java libraries and put into the library/build.gradle (code below), and added a reference to library in the application/build.gradle (code below).
settings.gradle:
rootProject.name = 'order-routing'
include 'library'
include 'application'
library/build.gradle:
buildscript {
repositories { mavenCentral() }
}
plugins {
id "io.spring.dependency-management" version "1.0.5.RELEASE"
}
apply plugin: 'project-report'
apply plugin: 'java'
ext { springBootVersion = '2.1.6.RELEASE' }
jar {
baseName = 'order-routing-library'
version = '0.0.1-SNAPSHOT'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
compileOnly 'com.google.code.gson:gson:2.8.5'
runtimeOnly 'com.h2database:h2:1.4.197'
compile 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.0.14'
}
and application/build.gradle (notice I added "compile project(':library')") :
buildscript {
ext { springBootVersion = '2.1.6.RELEASE' }
repositories { mavenCentral() }
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
plugins {
id "io.spring.dependency-management" version "1.0.5.RELEASE"
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
id "org.flywaydb.flyway" version "5.2.4"
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'project-report'
apply plugin: "maven"
apply plugin: 'docker'
repositories {
mavenCentral()
}
dependencies {
compile 'mysql:mysql-connector-java'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile project(':library')
}
sourceCompatibility = 8
targetCompatibility = 8
compileJava.options.compilerArgs.add '-parameters'
compileTestJava.options.compilerArgs.add '-parameters'
configurations {
all*.exclude group: "org.hibernate", module: "hibernate-entitymanager"
all*.exclude group: "org.apache.tomcat", module: "tomcat-jdbc"
}
flyway {
url = 'jdbc:mysql://localhost/ordb'
user = 'flyway'
table = 'schema_version'
}
bootJar {
baseName = 'order-routing-application'
version = '0.0.1-SNAPSHOT'
mainClassName = 'com.pokemonmerch.orderrouting.OrderRoutingApplication'
}
Expected result: run './gradlew build' and see a successful build.
Actual: Getting "error: cannot find symbol" on a bunch of lombok generated methods
As I understood you're trying to use lombok in the application module, but you added it as a compileOnly dependency to the library module. So, because it's compileOnly it's not passed as a transitive dependency to the application module.
Please add lombok dependecies to the application module directly or change compileOnly to compile(what I don't recommend to do).
P.S. Don't forget to turn on Annotation Processing in your IDE.
Actually, what I suggest - it's to create build.gradle in the root folder (order-routing/build.gradle) and move common dependencies there, under the subprojects sections (https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:subproject_configuration)

Resources