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

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
}

Related

Unable to push artifacts to mavenLocal in multimodule gradle project

I am trying to publish to my local repositories
I have a multi module project. For one of the sub project, I am trying to publish to local maven repo.
But nothing is pushed but task is success.
Am I missing something
plugins {
id 'org.springframework.boot' version "${gradleSpringBootPluginVersion}" apply false
id 'io.spring.dependency-management' version "${gradleSpringDependencyPluginVersion}"
id 'java'
id 'maven-publish'
}
group 'org.gagagag'
version '1.0-SNAPSHOT'
subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
}
repositories {
mavenLocal()
mavenCentral()
}
tasks.named('test') {
useJUnitPlatform()
}
}
I am checking maven repo, but cannot find the jar. Am I doing anything wrong.
As you are using the 'maven-publish' plugin, the repository does not need to be declared in the publishing block
Remove the repository, so it returns it to:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
then from the sub-project directory run the following which is included as part of the 'maven-publish' plugin:
./gradlew publishToMavenLocal
This will publish the jar to your local .m2 repository

intellij Gradle Sync Error : "Could not resolve all artifacts for configuration ':classpath'."

This is my build.gradle
buildscript {
ext {
springBootVersion = '2.1.7.REALEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web:')
testCompile('org.springframework.boot:spring-boot-starter-test:')
}
and this is the Sync ErrorMessage
Could not resolve all artifacts for configuration ':classpath'.
Could not find org.springframework.boot:spring-boot-gradle-plugin:2.1.7.REALEASE.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/2.1.7.REALEASE/spring-boot-gradle-plugin-2.1.7.REALEASE.pom
- https://jcenter.bintray.com/org/springframework/boot/spring-boot-gradle-plugin/2.1.7.REALEASE/spring-boot-gradle-plugin-2.1.7.REALEASE.pom
Required by:
project :
Possible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
There are clearly declared repositories like mavenCentral() and jcnenter(), but can't build it.
I was told jcenter no longer be serviced, so I changed dependencies and deleted jcenter().
This build is successfully worked.
buildscript {
ext{
springBootVersion = '2.1.7.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
test {
useJUnitPlatform()
}

How to import local external jar having spring cloud vault client dependency

I have a "multi-module" Gradle project named "utils". In that, I have created a new sub-project that will be used as a client for Hashicorp's Vault. I'll use this jar to my Spring Boot microservices as a dependency.
The goal is to have a common configuration for Vault and use it in all the services.
My problem is when I try to auto-wire the VaultTemplate object (presuming it will be added from this jar), in one of my Spring Boot microservices (say secrets-management-service), I could not achieve that.
For development purposes, I have included the jar as a local dependency. I have included both the build.gradle files.
External Jar: vault-client
group = 'com.example.learning'
version = '1.0.0-SNAPSHOT'
buildscript {
ext {
springVersion = '2.4.4'
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springVersion}"
}
}
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = '1.8'
ext {
springCloudVersion = '2020.0.2'
}
repositories {
mavenCentral()
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-vault-config'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
Microservice: secrets-management-service
plugins {
id 'org.springframework.boot' version '2.4.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example.learning'
version = ''
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
bootJar {
setArchivesBaseName("secret-management-service")
version("")
}
dependencies {
compile fileTree(dir: "${projectDir}/libs", include: "*.jar")
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
I found it myself. I had missed the below block in my vault-client jar and also forgot to remove "main" class.
bootJar {
enabled = false
}

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)

Gradle build doesn't add version to package

I'm creating a REST microservice using Spring Boot 2.0.0.M7 with Gradle 4.2.
When I build from Eclipse or run from console ./gradlew build, the produced package in build/libs is named $app.jar instead of $app-$version.jar.
What am I missing? my build.gradle is the same as the Spring Boot Docker GS guide, and this problem prevent docker image to be built because the jar can't be found.
Here is my build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.0.M7'
springCloudVersion = 'Finchley.M5'
gradleDockerVersion = '0.13.0'
}
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("gradle.plugin.com.palantir.gradle.docker:gradle-docker:${gradleDockerVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'networks'
version = '0.9'
}
group = 'test'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-data-rest'
compile 'org.springframework.boot:spring-boot-starter-json'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
runtime 'org.springframework.boot:spring-boot-devtools'
runtime 'org.postgresql:postgresql'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'junit:junit'
}
docker {
name "${project.group}/${jar.baseName}"
files jar.archivePath
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
The version should be specified outside jar:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = "0.9"
jar {
baseName = 'networks'
}

Resources