Migrating from Spring Boot 1.5.8 to 2.1.5, getting the error message:
Could not set unknown property 'sourceCompatibility' for project ':api' of type org.gradle.api.Project.
If I comment that line, I get the error message:
Could not set unknown property 'targetCompatibility' for project ':api' of type org.gradle.api.Project.
If I comment that line, I get the error message:
Could not find method jar() for arguments [build_4wobgm6qykoy29e0in3cntga8$_run_closure2#1fc9b06d] on project ':api' of type org.gradle.api.Project.
So something is just not right here. I have two build.gradle files, one in my root, one in api:
/build.gradle
plugins {
id 'idea'
id 'java'
id 'com.jfrog.bintray' version '1.8.4'
}
apply from: "$rootDir/gradle/git-version.gradle"
version getVersionFromGit()
group 'com.my_org.my_proj'
apply from: "$rootDir/gradle/bintray-vars.gradle"
subprojects {
repositories {
jcenter()
mavenCentral()
}
}
wrapper {
gradleVersion = '4.8.1'
}
/api/build.gradle
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.7.RELEASE'
}
group = rootProject.group
version = rootProject.version
repositories {
maven { url 'https://dl.bintray.com/my-org/spring-utils' }
}
apply from: "$rootDir/gradle/checkstyle.gradle"
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
archiveName = 'api.jar'
baseName = project.name
version = project.version
}
test {
doFirst {
environment "BUILD_NUMBER", "1"
}
}
dependencies {
def springBoot = '2.1.5.RELEASE'
runtime group: 'org.springframework.boot', name: 'spring-boot-properties-migrator', version: springBoot
compile group: 'org.flywaydb', name: 'flyway-core', version: '5.2.4'
compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.4.3.Final'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-freemarker', version: springBoot
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBoot
testCompile group: 'org.flywaydb.flyway-test-extensions', name: 'flyway-spring-test', version: '4.2.0.2'
}
I'm clearly missing something here. I've been following the migration guide as well as Googling, of course. Suggestions?
You haven't applied the java plugin to your api sub-project so the sourceCompatibility and targetCompatibility properties that it adds to the project are missing as is the jar task that it defines.
Adding id java to the plugins block at the top of api/build.gradle should fix the problem.
Related
I'm facing this error while running the project. I'm unable to know the cause of the error and unable to find a solution online as well.
This project is running over another laptop without any error but when I extracted the zip and tried to run it, found it throwing error.
Please help me figure this out. Thanks
Error
Execution failed for task ':Application.main()'.
Process 'command '/home/jamshaid/Documents/idea-IC-192.5728.98/jbr/bin/java'' finished with non-zero exit value 1
StackTrace
2019-08-11 09:57:06,589 2269 [main] INFO com.techno.homes.Application - No active profile set, falling back to default profiles: default
2019-08-11 09:57:06,628 2308 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.AbstractMethodError: Receiver class org.springframework.cloud.bootstrap.BootstrapApplicationListener$CloseContextOnFailureApplicationListener does not define or inherit an implementation of the resolved method abstract getOrder()I of interface org.springframework.core.Ordered.
at org.springframework.core.OrderComparator.findOrder(OrderComparator.java:142)
at org.springframework.core.annotation.AnnotationAwareOrderComparator.findOrder(AnnotationAwareOrderComparator.java:65)
at org.springframework.core.OrderComparator.getOrder(OrderComparator.java:125)
at org.springframework.core.OrderComparator.getOrder(OrderComparator.java:113)
at org.springframework.core.OrderComparator.doCompare(OrderComparator.java:82)
at org.springframework.core.OrderComparator.compare(OrderComparator.java:68)
at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:360)
at java.base/java.util.TimSort.sort(TimSort.java:220)
at java.base/java.util.Arrays.sort(Arrays.java:1515)
at java.base/java.util.ArrayList.sort(ArrayList.java:1749)
at org.springframework.boot.SpringApplication.asUnmodifiableOrderedSet(SpringApplication.java:1325)
at org.springframework.boot.SpringApplication.getListeners(SpringApplication.java:1234)
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:85)
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:66)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:394)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:328)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
at com.techno.homes.Application.main(Application.java:24)
Gradle File
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
apply plugin: 'docker'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'}
buildscript {
project.ext {
springBootVersion = '2.0.4.RELEASE'
jarName = 'recipe'
versionName = '1.0.0'
gradleDockerVersion = '1.2'
swagger2version = '2.9.2'
}
repositories {
jcenter()
maven { url "https://repo.maven.apache.org/maven2" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle- plugin:${project.springBootVersion}"
classpath "se.transmode.gradle:gradle-docker:${project.gradleDockerVersion}"
}
}
task createWrapper(type: Wrapper) {
gradleVersion = '4.4.1'
}
// Used by the Docker gradle plugin, group refers to the account under which the docker image is created
group = 'com.techno.homes'
mainClassName = 'com.techno.homes.Application'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
jcenter()
}
ext {
springCloudVersion = 'Greenwich.SR2'
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '2.0.4.RELEASE'
compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.0.16.Final'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web-services', version: '2.0.4.RELEASE'
compile group: 'ma.glasnost.orika', name: 'orika-core', version: '1.4.6'
compile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.springframework.boot', name: 'spring-boot-test-autoconfigure', version: '2.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-test', version: '5.1.8.RELEASE'
compile(group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.4.3.Final')
compile(group: 'org.hibernate', name: 'hibernate-core', version: '5.2.17.Final')
compile group: 'org.springframework.boot', name: 'spring-boot-test'
compile group: 'org.mockito', name: 'mockito-core', version: '2.15.0'
compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.4'
compile group: 'info.cukes', name: 'cucumber-core', version: '1.2.4'
compile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.4'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '2.0.1'
compile group: 'com.spotify', name: 'docker-maven-plugin', version: '1.2.0'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.46'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version: '1.58'
testCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
// Basic Spring boot with config client
// compile('org.springframework.cloud:spring-cloud-starter-config')
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
// Spring OAuth2 security
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.security.oauth:spring-security-oauth2")
// compile("org.springframework.security:spring-security-jwt")
compile group: 'org.springframework.security', name: 'spring-security-jwt', version: '1.0.10.RELEASE'
// Eureka client
// compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client', version: '2.0.0.RELEASE'
// Zipkin tracing
//compile('org.springframework.cloud:spring-cloud-starter-zipkin')
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zipkin', version: '2.1.2.RELEASE'
// Swagger for API testing
compile("io.springfox:springfox-swagger2:${swagger2version}")
compile("io.springfox:springfox-swagger-ui:${swagger2version}")
compile group: 'org.springframework.security', name: 'spring-security-core', version: '5.1.5.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-config', version: '5.1.5.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-web', version: '5.1.5.RELEASE'
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.3.6.RELEASE'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
//camel
compile group: 'org.apache.camel', name: 'camel-spring-boot', version: '2.15.1'
compile group: 'org.apache.camel', name: 'camel-pulsar', version: '2.24.1'
compile group: 'org.apache.camel', name: 'camel-core', version: '2.24.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9.3'
}
jar {
baseName = "${project.jarName}"
version = "${project.versionName}"
enabled = true
manifest {
attributes 'Main-Class': 'com.techno.homes.Application'
}
}
Allication
#Configuration
#EnableJpaAuditing
#EnableJpaRepositories("com.techno.homes.repositories")
#SpringBootApplication
#EnableEurekaClient
#EnableResourceServer
#EnableSwagger2
#EnableOAuth2Client
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Your Spring Boot version is too old for your Spring Cloud version:
https://github.com/spring-cloud/spring-cloud-commons/issues/552
Spring Cloud Greenwich (2.1.x) is not compatible with spring boot 2.0.x and spring framework 5.0.x. Either update spring boot or downgrade spring cloud to Finchley.
So please update Spring Boot to 2.1.x
PS: searching on 'BootstrapApplicationListener$CloseContextOnFailureApplicationListener' would have lead you there straight away :-)
Ok - did some testing here.
Created empty SpringBoot application from start.spring.io.
Imported the project into IntelliJ.
I then loaded your gradle file contents. Also started by removing all the # imports in the main (Application) class - just kept #SpringBootApplication.
Removed all the other classes (including tests).
Had same error.
Started by removing all the gradle dependencies for Swagger and Hibernate, etc. Those are not required to get a bare-bones SpringBoot app running.
Removing this line solved to error (not throwing the error anymore):
compile("org.springframework.security.oauth:spring-security-oauth2")
So something needs to be configured if you want to do Spring OAuth2 ... for you to find.
Suggest you add small building blocks at a time - you have a lot of stuff in the SpringBoot main app annotated. Spring will auto-configure defaults for all it can, but you might run into similar problems.
Add one annotation - write unit test class that will verify basic functionality of that specific annotation. Then enable the next one, write unit test.... unit all are working with basic test coverage.
This is because of spring and cloud version not compatible.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath />
</parent>
The version of the parent should be an upgrade one or the same as cloud version.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
I have created a relatively new project with 4 modules inside one project (created with intelij). However, I have now got to the stage where I want to import one module (:domain) from another (app-updater). The issue I'm facing is when I do this from within intelij it gives me errors in the "Build: Sync" tab. This is strange since my module app-updater is able to reference to module domain when I add the line "compile project(':domain')" into build.gradle and when I remove the line I get issues with the class being missing so the build: sync seems to be working it's just running it from inside intelij seems to give an error saying "Project with path ':domain' could not be found in root project 'app-updater'." I have attached my gradle config below, hopefully I have given enough info but if not feel free to ask for more, thanks for any help.
Main project settings.gradle file
rootProject.name = 'rGuide'
include 'domain'
include 'service'
include 'app-updater'
include 'app-rest'
:domain build.gradle
group 'domain'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.9'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
app-updater build.gradle file
group 'app-updater'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
google()
maven {
url 'https://repo.spring.io/plugins-release/'
}
maven {
url 'https://repo.spring.io/milestone'
}
}
dependencies {
compile project(':domain')
// https://mvnrepository.com
compile group: 'net.ser1', name: 'gozirra-client', version: '0.4.1'
compile group: 'io.netty', name: 'netty-all', version: '4.1.36.Final'
compile group: 'io.projectreactor.netty', name: 'reactor-netty', version: '0.9.0.M2'
compile group: 'org.springframework.integration', name: 'spring-integration-stomp', version: '5.1.6.RELEASE'
compile group: 'org.springframework.integration', name: 'spring-integration-core', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-websocket', version: '5.1.6.RELEASE'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.9'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
TLDR - Trying to import domain into app-updater within intelij, it "works fine" and seems to import domain however when I do this with the Build: sync tab in intelij it gives an error saying "Project with path ':domain' could not be found in root project 'app-updater'.". Thanks for any help!!
I am trying to add ajc compiler to my gradle project as gradle plugin. Unfortunately, during compilation it shows me massive amount of errors due to Lombok.
build.gradle:
group 'com.kmb.bank'
version '0.0.1-SNAPSHOT'
project.ext {
aspectjVersion = '1.9.2'
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.aspectj:gradle-aspectj:0.1.6"
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "aspectj.gradle"
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
implementation('org.springframework.boot:spring-boot-starter-amqp')
implementation('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile ('org.springframework.boot:spring-boot-starter-security')
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile group: 'org.springframework.boot', name: 'spring-boot-starter- aop', version: '2.1.1.RELEASE'
}
It shows me errors that there are no getter, setters for every model.
This is working for me:
plugins {
id 'java'
id "io.freefair.aspectj.post-compile-weaving" version "4.1.4"
}
group 'com.amdocs'
version '1.0.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.10'
annotationProcessor "org.projectlombok:lombok:1.18.10"
}
I'm using Spring Boot for a school project as a personal choice but the automated tester uses ./gradlew appRun to start the whole thing up.
This was fine before when they were using servlets but after moving to Spring Boot, I'm getting several exceptions when trying to do so.
Execution failed for task ':appRun'.
Could not get unknown property 'mainClass' for object of type org.springframework.boot.gradle.dsl.SpringBootExtension.
and this is my current build.gradle.
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath "gradle.plugin.org.akhikhl.gretty:gretty:2.0.0"
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'org.gretty' version '2.2.0'
id 'war'
}
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "org.akhikhl.gretty"
apply plugin: 'application'
sourceCompatibility = 8
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
runtimeOnly('com.h2database:h2')
runtimeOnly('mysql:mysql-connector-java')
runtimeOnly('org.hsqldb:hsqldb')
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.7'
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'org.apache.ibatis', name: 'ibatis-core', version: '3.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'
compile group: 'org.apache.ibatis', name: 'ibatis-core', version: '3.0'
compile group: 'org.gretty', name: 'gretty-runner-jetty94', version: '2.2.0'
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
providedRuntime ('org.springframework.boot:spring-boot-starter-tomcat')
runtimeOnly('mysql:mysql-connector-java')
compileOnly('org.projectlombok:lombok')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
gretty {
contextPath = '/'
}
This all works fine when using ./gradlew bootRun but that doesn't pass the automated tester.
Is there a way to make running ./gradlew appRun start up the SpringBoot main class similarly or directly ./gradlew bootRun?
This is a gretty question. Add this line to gretty config:
gretty {
contextPath = '/'
springBoot = true
}
Here's the doc: http://akhikhl.github.io/gretty-doc/spring-boot-support.html
I am using spring Boot.I created Spring boot gradle application.I got following error.
Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter
build.gradle
buildscript {
ext {
springBootVersion = '1.3.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile group: 'org.springframework', name: 'spring-web', version: '4.0.0.RELEASE'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.12'
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.12'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.2'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.2.2'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.2'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
Am I missing any dependency in build.gradle?
How to solve this?
You are including two different versions of the jackson lib. For Spring 4+ use the com.fasterxml.jackson.core like you have. Remove the two org.codehaus.jackson dependencies.