compile find a bad version of gradle - spring-boot

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

Related

Trouble consuming Gradle plugin project with 3rd party maven repository

I am attempting to create a Gradle plugin that is set up like this:
plugins {
id 'java-gradle-plugin'
id 'groovy'
}
repositories {
mavenCentral()
jcenter()
// note the custom maven repo
maven { url = "https://maven.gentics.com/maven2" }
}
dependencies {
implementation gradleApi(),
localGroovy(),
"com.gentics.mesh:mesh-rest-client:${MESH_VER}"
testImplementation gradleTestKit()
testImplementation("org.spockframework:spock-core:${SPOCK_VER}") {
exclude module : 'groovy-all'
}
}
// the rest...
However if I try to consume this plugin in another project with includeBuild "./gradle-mesh" in the settings.gradle, I get the following error:
A problem occurred configuring root project 'functionalTest'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.gentics.mesh:mesh-rest-client:1.7.1.
Searched in the following locations:
- https://plugins.gradle.org/m2/com/gentics/mesh/mesh-rest-client/1.7.1/mesh-rest-client-1.7.1.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project : > project :gradle-mesh
However, I am able to execute the functionalTest in the actual plugin tests without issue. Getting rid of that line in the settings.gradle and renaming the folder to buildSrc works as well.
Is there a way to configure the buildscript dependencies from within the plugin entry point? I tried the following, but it didn't make any difference.
class GradleMeshPlugin implements Plugin<Project> {
public void apply(Project project) {
project.buildscript.repositories.configure {
mavenLocal()
jcenter()
maven { url = "https://maven.gentics.com/maven2" }
}
// dependency is referenced here...
}
}
Any ideas how to go about this?
Full Project: https://github.com/wawebio/gradle-mesh
System:
------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------
Build time: 2020-08-25 16:29:12 UTC
Revision: f2d1fb54a951d8b11d25748e4711bec8d128d7e3
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 11.0.8 (Ubuntu 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OS: Linux 5.4.0-47-generic amd64
Update
I was also able to get it to work by adding the following in the consuming project's settings.gradle
pluginManagement {
repositories {
mavenCentral()
jcenter()
maven { url = "https://maven.gentics.com/maven2" }
}
}
rootProject.name = 'website'
includeBuild "./gradle-mesh"
Is there a way to do this from within the plugin application itself?
You need to specify your mvn package‌‌‌​​‌​‌‌​‌‌‌‌‌‌​​​‌​‌‌​‌‌‌‌ differently, which is the first one.
<configuring-project>

Gradle Kotlin allprojects dependencies cause build failure

In my Gradle project, I can declare a dependencies block with implementation entries, no problem. When I try to declare something like this, however, I get an error:
allprojects {
dependencies {
implementation("...")
}
}
The error I get:
Could not find method implementation() for arguments [org.mockito:mockito-core:2.25.0]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I wasn't able to reproduce this with a Java project, so it might have something to do with the Kotlin project. I'm new to Gradle, so I might just be doing something silly? Here's my environment info:
$ gradle --version
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_112 (Oracle Corporation 25.112-b15)
OS: Windows 10 10.0 amd64
Minimal reproduction
I can reproduce the issue with a minimal project.
build.gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
// This works.
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
// Causes an error. Using a random dependency to reproduce the issue.
allprojects {
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
settings.gradle:
rootProject.name = 'demo'
// Removing this line causes the error to go away, but means the module is missing.
include 'submodule'
submodule/build.gradle
// Empty file. I've tried adding various plugins (java / kotlin) to no avail.
The issue in your build.gradle is you are trying to use a build dependency configuration, in this case implementation without specifying the java plugin. The gradle docs says;
The Java plugin adds a number of dependency configurations to your
project, as shown below. Tasks such as compileJava and test then use
one or more of those configurations to get the corresponding files and
use them, for example by placing them on a compilation or runtime
classpath.
One way to fix this is to include java plugin as below (I have tested on 5.2.1 and it worked fine);
allprojects {
apply plugin: 'java'
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
The relationship of build configuration to the java plugin has been comprehensively described on
https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
and
https://docs.gradle.org/current/userguide/managing_dependency_configurations.html#managing_dependency_configurations
Also, make sure you don't duplicate this dependency (or any other which is declared in the root or for all projects) in subprojects.

Gradle 4.7 build throw error executing task bootRepackage

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'
}

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