I've been using gradle for Springboot and it used to be fine but all of the sudden the gradle build stopped working. I keep getting errors saying that dependencies can't be found.
Here is the gradle code:
plugins {
id 'org.springframework.boot' version '2.4.1'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
version = '0.0.1'
sourceCompatibility = '1.8'
repositories {
maven {
url 'https://repo1.maven.org/'
}
}
springBoot {
buildInfo()
}
ext {
set('springCloudServicesVersion', "2.4.1")
set('springCloudVersion', "2020.0.3")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.pivotal.spring.cloud:spring-cloud-services-starter-config-client'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'org.springframework.boot:spring-boot-starter-integration'
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation 'org.springframework.integration:spring-integration-test'
implementation 'org.springframework.integration:spring-integration-mail:5.5.1'
implementation group: 'javax.mail', name: 'mail', version: '1.5.0-b01'
implementation group: 'org.apache.velocity.tools', name: 'velocity-tools-generic', version: '3.0'
implementation 'org.jsoup:jsoup:1.14.1'
implementation 'com.microsoft.sqlserver:mssql-jdbc:7.4.1.jre8'
}
dependencyManagement {
imports {
mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:${springCloudServicesVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
The errors I'm getting:
Could not resolve org.springframework.boot:spring-boot-dependencies:2.4.1.
Could not resolve io.pivotal.spring.cloud:spring-cloud-services-dependencies:2.4.1.
Could not resolve org.springframework.cloud:spring-cloud-dependencies:2020.0.3.
Any Ideas?
Your maven repository is wrong.
Change
repositories {
maven {
url 'https://repo1.maven.org/'
}
}
to
repositories {
mavenCentral()
}
See here a good explanation on how to declare the maven repository in your build.gradle file.
Related
i try to use conf files from lib, but applcation.yaml dont see classpath to lib
this is my gradle.build
image of apllication.yaml
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.6'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'common'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.mockito:mockito-core:4.9.0'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation group: 'ma.glasnost.orika', name: 'orika-core', version: '1.5.4'
implementation 'common:0.3.2'
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.13'
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc8', version: '21.7.0.0'
implementation 'org.postgresql:postgresql'
implementation 'org.jetbrains:annotations:23.0.0'
implementation 'org.springframework.boot:spring-boot-starter-cache:2.7.6'
implementation 'org.springframework.boot:spring-boot-starter-data-redis:2.7.6'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Can someome explain me what i do wrong?
Everything you have in libs directory needs to go to src/main/resources. Then it will be visible on the classpath.
I have a Gradle project into which I want to implement Java class with querydsl. I tried this implementation:
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'test'
version = '0.0.1'
sourceCompatibility = '17'
ext {
set('springCloudVersion', "2021.0.2")
queryDslVersion = '5.0.0'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.hibernate.validator:hibernate-validator'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'joda-time:joda-time:2.10.14'
implementation 'org.springframework.boot:spring-boot-starter-hateoas:2.6.7'
implementation 'org.postgresql:postgresql'
implementation 'org.jadira.usertype:usertype.core:7.0.0.CR1'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.2'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'com.google.code.gson:gson:2.9.0'
// QueryDSL
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jpa"
testImplementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
testAnnotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jpa"
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
// Swagger
implementation 'org.springdoc:springdoc-openapi-ui:1.6.8'
implementation 'org.liquibase:liquibase-core'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
But JPA classes are not generated. I get exception:
import com.test.domain.QTransaction;
^
symbol: class QTransaction
location: package com.test.domain
Do you know what is the proper way to implement this?
I am new to Gradle and I followed the instructions of a tutorial, just that instead of maven I chose Gradle in Spring.Initializr.
It produced following code for the build.gradle
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.microservicetest'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.0")
}
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
import group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: '2021.0.0', ext: 'pom'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-config-server'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
I receive the error message
Could not compile build file '/home/max/IdeaProjects/Restaurant Rating App/build.gradle'.
> startup failed:
build file '/home/max/IdeaProjects/Restaurant Rating App/build.gradle': 20: Unexpected input: ':' # line 20, column 13.
import group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: '2021.0.0', ext: 'pom'
What is wrong with the autogenerated code?
Thanks!
The build.gradle in your question matches the expected output from start.spring.io except these two lines:
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
import group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: '2021.0.0', ext: 'pom'
This is not valid Gradle syntax. Simply removing them will fix the issue at hand.
I am running into the following error when i try to build my spring boot project in gradle. I got the build.gradle from the spring initilizer.
Could not resolve all artifacts for configuration ':classpath'.
Could not find spring-boot-gradle-plugin-2.3.0.BUILD-SNAPSHOT.jar (org.springframework.boot:spring-boot-gradle-plugin:2.3.0.BUILD-SNAPSHOT:20200409.145011-519).
Searched in the following locations:
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-gradle-plugin/2.3.0.BUILD-SNAPSHOT/spring-boot-gradle-plugin-2.3.0.BUILD-20200409.145011-519.jar
Please find my gradle build
plugins {
id 'org.springframework.boot' version '2.3.0.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.mycompany'
version = '0.0.1-SNAPSHOT' //TODO how does verioning work in this project?
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.springframework.boot:spring-boot-starter-aop'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation ('org.springframework.integration:spring-integration-test'){
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation ('org.springframework.kafka:spring-kafka-test'){
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}
test {
useJUnitPlatform()
}
If you do not have a special reason to use specifically the SNAPSHOT version I suggest using release or milestone.
SNAPSHOT builds are quite unstable. If you want to take a look at the new 2.3 version of the Spring Boot you should probably use the milestone version. For today it would be 2.3.0.M4.
For that, change org.springframework.boot plugin version like this:
id 'org.springframework.boot' version '2.3.0.M4'
I am trying to implement hibernate metamodel in my spring boot application. I am getting
Annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' not found
above error, while building applications.
My Gradle configuration and detailed error given below
buildscript {
ext {
springBootVersion = '2.2.6.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('se.transmode.gradle:gradle-docker:1.2')
classpath("gradle.plugin.at.comm_unity.gradle.plugins:jpamodelgen-plugin:1.1.4")
}
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "jacoco"
apply from: 'docker.gradle'
apply plugin: "at.comm_unity.gradle.plugins.jpamodelgen"
sourceCompatibility = 1.8
bootJar {
launchScript()
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-quartz'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.jsonwebtoken:jjwt-api:0.10.5'
implementation 'org.flywaydb:flyway-core'
compileOnly 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.10.5'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor('org.hibernate:hibernate-jpamodelgen:5.4.14.Final')
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
}
test.reports.junitXml.setDestination(file("${buildDir}/test-results"))
jacocoTestReport {
reports {
html.destination file("${buildDir}/jacocoHtml")
}
}
jpaModelgen {
library = "org.hibernate:hibernate-jpamodelgen"
jpaModelgenSourcesDir="src/jpaModelgen/java"
}
sourceSets {
main {
java {
srcDirs += "src/jpaModelgen/java"
}
}
}
While running the application with ./gradlew build --info i am getting below error
Im using spring-boot 2.2.6, Is there any version compatibility available for hibernate-jpamodelgen.
You don't need to use any plugin to generate JPA metamodel. It is enough to use the line
annotationProcessor 'org.hibernate.orm:hibernate-jpamodelgen:<6.1.1.Final now or other version>'
in build.gradle dependencies block.