Unable to build SpringBootProject from terminal i.e command line - spring-boot

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()
}

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()
}

How to resolve invalid packaging for parent POM, must be "pom" but is "jar"

To resolve spring-framework vulnerability posted by spring.io
I tried upgrading spring-boot version from 2.4.5 to 2.5.12 and with gradle-6.8 version, on running ./gradlew clean build task is failing with error
Invalid packaging for parent POM org.apache.logging.log4j:log4j-api:2.17.2, must be "pom" but is "jar" in org.apache.logging.log4j:log4j-api:2.17.2
The dependency org.springframework.boot:spring-boot-starter-webflux loads the internal dependency log4j-api:2.17.2
How to resolve invalid parent POM packaging for internal dependencies?
build.gradle
buildscript {
ext {
springBootVersion = '2.5.12'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
{
exclude group: 'org.slf4j', module: 'slf4j-ext'
}
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.service'
version = ''
sourceCompatibility = 11
def logbackVersion = '1.2.3'
repositories {
mavenCentral()
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.apache.logging.log4j') {
details.useVersion '2.17.1'
}
}
}
dependencies {
implementation ('org.springframework.boot:spring-boot-starter-webflux')
developmentOnly('org.springframework.boot:spring-boot-devtools')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('io.projectreactor:reactor-test')
implementation("ch.qos.logback:logback-core:${logbackVersion}")
implementation("ch.qos.logback:logback-classic:${logbackVersion}")
implementation('org.apache.httpcomponents:httpclient:4.5.11')
implementation('org.apache.commons:commons-collections4:4.4')
implementation("org.springframework.cloud:spring-cloud-vault-config:2.1.3.RELEASE")
implementation("org.springframework.cloud:spring-cloud-vault-config-consul:2.1.3.RELEASE")
implementation group: 'org.springframework.cloud', name: 'spring-cloud-consul-dependencies', version: '1.0.0.RELEASE', ext: 'pom'
implementation('com.amazonaws:aws-java-sdk-sqs:1.11.634')
implementation('org.projectlombok:lombok:1.18.12')
implementation('org.yaml:snakeyaml:1.26')
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
annotationProcessor('org.projectlombok:lombok:1.18.12')
implementation group: 'org.bouncycastle', name: 'bc-fips', version: '1.0.2'
implementation group: 'org.bouncycastle', name: 'bctls-fips', version: '1.0.11'
}
Adding mavenBom spring-cloud-dependencies helped resolve this issue. Suspecting webflux pulled in a transitive dependency to an older release and adding spring-cloud-dependencies bom in dependencyManagement ensured all Spring dependencies are at the same version
Here's update build.gradle file that worked
plugins {
id 'org.springframework.boot' version '2.6.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'application'
}
group = 'com.service'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '11'
application {
mainClass = 'com.service.scheduler.SchedulerApplication'
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.1")
set('logbackVersion', "1.2.11")
}
bootJar {
archiveFileName = 'scheduler.jar'
}
bootRun {
systemProperties = System.properties
}
dependencies {
/*---spring dependencies---*/
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.cloud:spring-cloud-starter-vault-config'
implementation 'org.springframework.cloud:spring-cloud-vault-config-consul'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
implementation 'com.amazonaws:aws-java-sdk-sqs:1.12.187'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation 'org.apache.commons:commons-collections4:4.4'
implementation 'org.yaml:snakeyaml:1.30'
implementation 'com.google.code.gson:gson:2.9.0'
/*---fips dependencies---*/
implementation group: 'org.bouncycastle', name: 'bc-fips', version: '1.0.2'
implementation group: 'org.bouncycastle', name: 'bctls-fips', version: '1.0.11'
/*---lombok dependencies---*/
implementation 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
/*---logback dependencies---*/
implementation("ch.qos.logback:logback-core:${logbackVersion}")
implementation("ch.qos.logback:logback-classic:${logbackVersion}")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

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

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.

Why subproject dependency jar includes all dependencies in it?

My project consists of multiple modules like core, my-backend, university, learning, etc.
Core is module which is required in all rest modules.
When I create build of my-backend module, I see core is being added with all dependencies in it which is making that jar too big. Seems some issue with my gradle file which is causing this problem.
Also somehow application.yml from core module is not being loaded from my-backend module. Any Idea why?
My gradle file is as follows:
buildscript {
ext {
springBootVersion = '2.2.1.RELEASE'
internalUrl = 'http://internal/repository'
}
repositories {
mavenLocal()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "http://repo.spring.io/release" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.15'
}
}
plugins {
id "io.freefair.lombok" version "3.8.4" apply false
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'
apply from: "$rootDir/dependencies.gradle"
mainClassName = "com.myk.MyApp"
group = 'com'
version = app.version
description = """"""
sourceCompatibility = 11
targetCompatibility = 11
ext {
set('springCloudVersion', "Hoxton.RC1")
}
repositories {
mavenLocal()
maven { url "http://repo.spring.io/libs-snapshot" }
jcenter()
mavenCentral()
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "http://maven.aksw.org/repository/internal" }
maven { url "https://dl.bintray.com/michaelklishin/maven/" }
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
// additional plugins
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "io.freefair.lombok"
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.cloud:spring-cloud-stream-test-support'
testImplementation (group: 'com.github.javafaker', name: 'javafaker', version: ver.'javafaker') {
exclude group: 'org.yaml', module: 'snakeyaml'
}
}
test {
useJUnitPlatform()
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
}
project(':core') {
dependencies {
implementation group: 'com.github.fommil.netlib', name: 'all', version: '1.1.2' // weka dependency
implementation 'org.springframework.boot:spring-boot-configuration-processor:2.2.1.RELEASE'
implementation group: 'com.google.firebase', name: 'firebase-admin', version: ver.'firebase-admin'
implementation group: 'com.google.apis', name: 'google-api-services-gmail', version: ver.'google-api-services-gmail'
compile "org.quartz-scheduler:quartz:${ver.quartz}"
}
}
[
':university',
':my-backend',
':learning'
].each {
project(it) {
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'io.spring.dependency-management'
mainClassName = "com.myk.MyApp"
springBoot {
buildInfo()
}
dependencies {
compile project(':core')
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testCompile group: 'io.github.swagger2markup', name: 'swagger2markup', version: ver.'swagger2markup'
}
}
}

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