Gradle 4.7 build throw error executing task bootRepackage - spring-boot

While executing gradle build command in my existing spring boot project which was / is building fine with older version of Gradle (For ex: 3.4.*).
But after I upgraded Gradle to latest version (4.7) using SDK, its started throw error while building.
Config List:
------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------
Build time: 2018-04-18 09:09:12 UTC
Revision: b9a962bf70638332300e7f810689cb2febbd4a6c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_121 (Oracle Corporation 25.121-b13)
OS: Linux 3.16.0-4-amd64 amd64
Spring Boot Details:
springBootVersion = '1.5.1.RELEASE'
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
build.gradle Note: I can't publish whole build file. So giving some import lines to analyse.
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}"
}
}
subprojects {
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'war'
apply plugin: 'org.sonarqube'
// make sure bootRepackage is included in task graph
project.tasks.findAll { it.name.startsWith("artifactory") } .each { it.dependsOn assemble }
// so we can maintain both "normal" and "boot" jars
springBoot {
classifier = 'boot'
}
publishing {
publications {
mavenJava(MavenPublication) {
// from components.java
// "boot" jar
artifact ("$buildDir/libs/${project.name}-${version}-boot.war") {
classifier = 'boot'
}
}
}
}
def profiles = 'development'
bootRun {
args = [
"--spring.profiles.active=" + profiles
]
}
defaultTasks 'bootRun'
// Other tasks and dependency list
}
Output from Command Line:
gradle build
Task :test-service:bootRepackage FAILED
> FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.7/userguide/command_line_interface.html#sec:command_line_warnings

Spring Boot 1.5.x only supports Gradle 2 (2.9 or later) and Gradle 3. Gradle 4 is not supported.
You could either stick with Gradle 3.x or upgrade to Spring Boot 2.0.x which does support Gradle 4.

The error clearly states that -
* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class
Please check if you have entry similar in your build.gradle
apply plugin: 'application'
mainClassName = 'com.my.MyApplication' // your application main class goes here

According to this question, you have to set the main class :
bootRepackage {
mainClass = 'your.app.MainClass'
}

Related

Gradle: Could not get unknown property 'classesDir' for main classes

According to the documentation, I've tried to use aspectj plugin.
This is the message I get when I build my project.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jesudi/projects/gradle-vscode/build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'security'.
> Failed to apply plugin [id 'aspectj.gradle']
> Could not create task ':compileAspect'.
> Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.
This is my script:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.apache.meecrowave:meecrowave-gradle-plugin:1.2.6"
classpath "gradle.plugin.aspectj:gradle-aspectj:0.1.6"
}
}
plugins {
id 'java'
}
project.ext {
aspectjVersion = '1.9.2'
}
apply plugin: 'aspectj.gradle'
apply plugin: "org.apache.microwave.microwave"
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
compile("org.apache.meecrowave:meecrowave-core:1.2.6")
compile("org.apache.meecrowave:meecrowave-specs-api:1.2.6")
}
meecrowave {
httpPort = 9090
// most of the meecrowave core configuration
}
This is the gradle -version output:
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------
Build time: 2019-01-10 23:05:02 UTC
Revision: 3c9abb645fb83932c44e8610642393ad62116807
Kotlin DSL: 1.1.1
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Linux 4.15.0-20-generic amd64
In Gradle 5.x, this property has been renamed to classesDirs from classesDir.
You can find more information here
Possible your plugin is not a root of problem but the version of Gradle is.
First time I had the same error in libgdx game (android studio).
In build.gradle(desktop) file "classDir was renamed to classesDirs and it helped.
from files(sourceSets.main.output.classesDirs)
The classesDir property was deprecated in gradle 4.x, and removed in gradle 5.x (see the release notes).
The plugin has apparently not been maintained.
I got a similar error message, not with this plugin but even with the HelloWorld app created by Grails (3.2.9). In my case, I already used sdkman to set my current Gradle to 3.5 instead of 5, but the problem persists. It turned out that the "grails" cli (https://github.com/grails/grails-core/blob/3.2.x/grails-shell/src/main/groovy/org/grails/cli/gradle/GradleUtil.groovy) uses the default sdkman version for Gradle (which is different from the "current" version).
From Grails 3.3.X, one can set "gradleWrapperVersion=3.5" in gradle.properties instead, or use GRAILS_GRADLE_HOME environment variable as before.

compile find a bad version of gradle

I use spring boot 2. In a multi java project.
I try to build my main library (no yet java file)
apply plugin: 'java-library-distribution'
plugins {
id 'org.springframework.boot' version '2.0.0.M7'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.0.M7'
compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.0.M7'
}
distributions {
main{
baseName = 'common-model'
}
}
sourceCompatibility = 1.8
tasks.withType(JavaCompile) {
options.compilerArgs = ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
}
In my gradle/wrapper, i have
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-bin.zip
error i get
caused by: org.gradle.api.internal.plugins.PluginApplicationException:
Failed to apply plugin [id 'org.springframework.boot']
Caused by: org.gradle.api.GradleException: Spring Boot plugin requires
Gradle 4.0 or later. The current version is Gradle 2.13
i don't find any 2.13 version
In my main project i have
buildscript {
ext {
springBootVersion = '2.0.0.M7'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
mainClassName = 'com.zirgon.EmailApplication'
group = 'com.zirgon'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
tasks.withType(JavaCompile) {
options.compilerArgs = ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile project(':common-model')
compile('org.springframework.boot:spring-boot-starter-mail')
compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
It's possible you might be building the project with gradle installed locally instead of using the wrapper i.e. using gradle build instead of ./gradlew build.
These are the steps I took to fix the same problem.
I had a new project with a build.gradle file, but did not have a copy of gradle wrapper in my project directory. I think this caused the default gradle version for my IDE to be used (IntelliJ) and this is an older version.
Gradle was already installed on my system.
Ran "gradle wrapper" in my project directory.
Edited ./gradle/wrapper/gradle-wrapper.properties and made sure "distributionUrl" was pointed at the gradle version I wanted (4.6 in my case).
Reran my build and the correct version was then downloaded and installed. Problem fixed.
I hope this helps someone!
I copied my gradle wrapper folder over from another project, and edited ./gradle/wrapper/gradle-wrapper.properties
I'm running Eclipse 2018-2019/STS 4.0/Buildship Gradle 3.0. I solved the problem by configuring Eclipse > Gradle > Properties.
Specifically:
Eclipse > Gradle > Update Gradle Project >
Error: Spring Boot plugin requires Gradle 4.0 or later. The current version is Gradle 3.4.1
Everything looked OK in Eclipse > Window > Installed Software So I checked my Windows user profile directory:
Directory of C:\Users\paulsm\.gradle\wrapper\dists
06/11/2017 09:14 AM <DIR> gradle-3.3-all
12/07/2018 06:23 PM <DIR> gradle-3.4.1-bin <-- Eclipse using this version
11/01/2018 02:38 PM <DIR> gradle-4.1-all
11/01/2018 02:50 PM <DIR> gradle-4.4-all
12/07/2018 03:02 PM <DIR> gradle-4.8.1-bin
Eclipse > Window > Preferences > Gradle > Gradle distribution > Changed from "Gradle wrapper" => "Specific version: 4.8.1"
Re-ran Eclipse > Gradle > Update Gradle Project => SUCCESSFUL
This effectively ignores the project's local gradle wrapper settings, and ensures that I'll have the "correct* settings for ALL my Eclipse projects going forward.
I can always re-configure Gradle on a per-project basis (reverting back to 3.4.1 or older) if I ever need to.
Another option is to change the Gradle wrapper properties.
Error message:
> Failed to apply plugin [id 'org.springframework.boot']
> Spring Boot plugin requires Gradle 4.4 or later. The current version is Gradle 4.0
Change the distributionUrl value in gradle-wrapper.properties (located in /gradle/wrapper/) from:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
Open gradle/wrapper/gradle-wrapper.properties and change distributionUrl property to 4.6 version or newer one.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

Gradle Spring Boot - spring jar versions are not automatically picked up

I am trying out a simple gradle spring boot application as per the below URL
https://spring.io/guides/gs/spring-boot/
This is my build.gradle file
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'my-jar'
version = '1.0.0'
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
testCompile "junit:junit"
}
I am using a local artifactory and my init.gradle has the buildscript configuration which is below
buildscript {
repositories {
maven {
url 'http://mylocalartifactory:8081/'
}
}
dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE" }
}
I get the below error when i try to run gradlew build
What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter-web:.
Looks like the version is not getting applied for the dependency.
What I understand is that the version will be defaulted by the spring-boot plugin .
Am I missing something ?
It works fine if I mention the version number in the dependency
dependencies {
compile "org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE"
testCompile "junit:junit"
}
Though I can make it work , it beats the purpose of using spring boot if I need to manually specify the spring version jar dependency .
Kindly revert back if you see any issue in my build.gradle or init.gradle

How do I run spring-boot 1.2.x executable jar

This is a continuation of another question that got partially answered. Since the question morphed, I thought I should open a question that is more inline with that.
I have a project that started out as a spring-boot 1.1.7.RELEASE and I started from a directory containing the jar and an application.properties file via:
java -jar edm-0.1.0.jar
Everything was right as rain until I upgraded to spring-boot 1.2.1.RELEASE. Now, when I try to start with java -jar the app appears to start but trying to login gives me an error that the /templates html pages aren't found.
It would appear that the preferred way to start spring-boot apps is:
gradle bootRun
This would appear to work as long as I am in the top level of my project directory. But if I move the jar file off to another directory, and try to run it, I get the error:
:temp$ gradle bootRun
FAILURE: Build failed with an exception.
* What went wrong:
Task 'bootRun' not found in root project 'temp'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
so when I run "gradle tasks" I can see that "bootRun" is not available:
:temp$ gradle tasks
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
dependencies - Displays all dependencies declared in root project 'temp'.
dependencyInsight - Displays the insight into a specific dependency in root project 'temp'.
help - Displays a help message
projects - Displays the sub-projects of root project 'temp'.
properties - Displays the properties of root project 'temp'.
tasks - Displays the tasks runnable from root project 'temp'.
I guess this is a spring-boot gradle issue, but I can't say for sure. My version:
:temp$ gradle -version
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
Build time: 2013-12-17 09:28:15 UTC
Build number: none
Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy: 2.2.0
JVM: 1.8.0_31 (Oracle Corporation 25.31-b07)
OS: Mac OS X 10.10.2 x86_64
And here is my build.gradle:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.8'
languageLevel = '1.8'
}
}
jacoco {
toolVersion = "0.7.0.201403182114"
}
project.ext {
springBootVersion = '1.2.1.RELEASE'
}
configurations {
querydslapt
}
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE")
}
}
jar {
baseName = 'edm'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/snapshot" }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies {
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
compile('com.android.tools.build:gradle:1.0.1')
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
I did read the documentation, but nothing seems to address why I am having this problem. I would really appreciate any help you can send my way.

Gradle maven-publish for Spring-Boot project throws error: Cannot find parent: org.springframework.boot:spring-boot-starter-parent for project

I am new to Gradle so any help with this error will be highly appreciated.
I am building a REST based service using Spring-boot. I want to publish the JAR file to the local maven repository so that my web application can use it. After trying many things, I finally settled for maven-publish plugin. Here is my build.gradle file
//Needed for spring-boot
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE")
}
}
apply plugin: 'eclipse'
// Apply the groovy plugin to add support for Groovy
apply plugin: 'groovy'
//apply Spring-boot plugin
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
// In this section you declare where to find the dependencies of your project
repositories {
mavenLocal()
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
group = "com.proto"
publishing {
publications {
maven(MavenPublication) {
groupId "${project.group}"
artifactId "${project.name}"
version "${project.jar.version}"
artifact sourceJar { classifier "sources" }
from components.java
pom.withXml {
asNode().appendNode('parent')
.appendNode('groupId', 'org.springframework.boot').parent()
.appendNode('artifactId', 'spring-boot-starter-parent').parent()
.appendNode('version', '1.1.8.RELEASE')
asNode().appendNode('repositories').appendNode('repository')
.appendNode('id', 'spring-releases').parent()
.appendNode('url', 'http://repo.spring.io/libs-release')
}
}
}
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
jar {
baseName = 'my-api'
version = '0.0.1'
}
task('execJar', type:Jar, dependsOn: 'jar') {
baseName = 'my-api'
version = '0.0.1'
classifier = 'exec'
from sourceSets.main.output
}
bootRepackage {
withJarTask = tasks['execJar']
}
// In this section you declare the dependencies for your production and test code
dependencies {
// We use the latest groovy 2.x version for building this library
compile 'org.codehaus.groovy:groovy-all:2.3.6'
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web")
// {
// exclude module: "spring-boot-starter-tomcat"
// }
// compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// We use the awesome Spock testing and specification framework
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'junit:junit:4.11'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('cglib:cglib:3.1')
}
// tag::wrapper[]
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
My problem is that, when I run:
gradle publishToMavenLocal
I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'MavenLocal'
> Unable to initialize POM pom-default.xml: Cannot find parent: org.springframework.boot:spring-boot-starter-parent for project: com.proto:proto-api:jar:0.0.1 for project com.proto:proto-api:jar:0.0.1
My gradle environment details:
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------
Build time: 2014-09-08 10:40:39 UTC
Build number: none
Revision: e6cf70745ac11fa943e19294d19a2c527a669a53
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_72 (Oracle Corporation 24.72-b04)
OS: Linux 3.13.0-39-generic amd64
What am I missing?
Thank you in advance for your help.
Ok, I have fixed the issue.
I am behind our corporate firewall, and had configured proxy correctly for gradle in ~/.gradle/gradle.properties file. But, I missed setting proxies for maven in ~/.m2/settings.xml file.
I configured our internal nexus repository to handle this issue but setting proxies block should work as well. Click here for maven settings.xml documentation
Same as #aardee, I am sitting behind our corporate firewall but it seems that my proxy settings (settings.xml) for maven local did not change anything. Fortunately we have our own maven repository that can proxy out and so I just replaced the repository in the generated pom and made sure that our company maven repository knows the relevant spring repos.
pom.withXml {
asNode().appendNode('parent')
.appendNode('groupId', 'org.springframework.boot').parent()
.appendNode('artifactId', 'spring-boot-starter-parent').parent()
.appendNode('version', '1.1.8.RELEASE')
asNode().appendNode('repositories').appendNode('repository')
.appendNode('id', 'spring-releases').parent()
.appendNode('url', 'http://my.mavenRepo.com/releases}
Replace http://my.mavenRepo.com/releases with your own maven repository.

Resources