I have a dependency problem in a gradle project and I do not know how to solve it.
I have a root project "project-root" and two subprojects "project-sub-a" and "project-sub-b".
The "project-sub-a" has a dependency from "project-sub-b".
The structure is:
project-root
|-settings.gradle
|-build.gradle
project-sub-a
|-build.gradle
project-sub-b
project-root:settings.gradle:
include 'project-sub-a', 'project-sub-b'
project-root:build.gradle:
plugins {
id "io.spring.dependency-management" version "1.0.8.RELEASE"
}
subprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java-library'
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-gradle-plugin
compile group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.1.7.RELEASE', ext: 'pom'
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.10.3'
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.2.6.RELEASE")
}
}
}
project-sub-a:build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
}
apply plugin: 'org.springframework.boot'
dependencies {
implementation project(':connection-service-common')
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
}
After ./gradlew build i get the following errors:
> Task :project-sub-b:compileJava
.../Pojo.java: error: package com.fasterxml.jackson.annotation does not exist
import com.fasterxml.jackson.annotation.JsonProperty;
and more ...
Does anybody know how to solve this issue? Thanks.
Looks like your are missing:
'com.fasterxml.jackson.core:jackson-annotations:2.10.3'
which (and a few other jackson jars) is a transitive dependency of
'org.springframework.boot:spring-boot-starter-web'
That is why project a does not complain. Because of that there is no need to put jackson in subprojects. Subproject a is getting it anyway.
Related
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'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.
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.
I'm just learning how to work with spring and I'm new in this. I tried to add thymeleaf to my project with Gradle dependency but It can not be resolved. I think my way of adding thymeleaf to project is wrong. What should i do?
This is my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
group 'com.aminsl'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.9.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.2.4.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
}
I would go to https://start.spring.io/, select the dependencies I need as shown below:
And then Generate the project.
Using the website gives me the below gradle file:
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
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') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
Looks like you are missing the right plugins in your build file.
I am trying to setup AWS Polly Java SDK with Gradle in IntelliJ by following this. I have already created a simple Spring Boot application using the spring intializr, so I added the items specified in the tutorial to my build.gradle file. When try to import
import com.amazonaws.services.polly.AmazonPollyClient
IntelliJ fails to resolve name polly.
This is my full build.gradle file
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'com.amazonaws:aws-java-sdk-s3'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Also IntelliJ complains that it can't resolve the name manvenBom in my build.gradle. I have already tried SO solutions to this like invalidate cache/restart but could not resolve the issue.
I used your build.gradle file to replicate the issue and was able to import AmazonPollyClient after making the following changes to the dependencies
dependencies {
compile 'com.amazonaws:aws-java-sdk-s3'
compile group: 'com.amazonaws', name: 'aws-java-sdk-polly', version: '1.11.67'
The Gradle version used 4.8