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.
Related
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'
}
I am a Gradle newby. I have the following project setup:
Root
core: contains spring boot 2 application
ui: angular 5 front-end application
Goal: I want to run 'gradle build' from my root folder and it should contain one jar file which includes the Angular app.
I got the 'ui' covered:
apply plugin: "com.moowork.node"
buildscript {
repositories globalRepositories
dependencies {
classpath "com.moowork.gradle:gradle-node-plugin:1.2.0"
}
}
node {
// based on current version of Angular 5
version = "8.9.1"
npmVersion = "5.6.0"
download = true
}
task buildAngular(type: NpmTask) {
args = ['run', 'build']
}
buildAngular.dependsOn(npm_install)
build.dependsOn(buildAngular)
The above gradle definition will build and generate the Angular files in the static backend core application.
The 'core' gradle build file looks like this (I excluded the dependencies), nothing special:
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'xxx.xxxxxx'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories globalRepositories
ext {
springBootVersion = '2.0.0.M7'
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
jar {
baseName = 'spring-boot-angular'
version = '1.0.0'
}
How can I make this possible? I want the following actions to be triggered when I run 'gradle build' from my root project:
run first 'gradle build' in ui
then second run 'gradle build' in core
use the generated jar file from 'core' as the end result
I can't stand the groovy like syntax, can't wait for Gradle Kotlin DSL to mature :P
Hope somebody can help. I will open source this setup (together with Spring 5, Hibernate 5 and flyway) when I get this up and ready. Thanks in advance.
You need to include the result of the frontend (ui) buildAngular task inside the jar generated in the backend (core) build:
bootJar {
dependsOn ':ui:buildAngular'
into('BOOT-INF/classes/static') {
from "${project(':ui').projectDir}/dist"
}
}
The fact that the bootJar task now depends on the buildAngular task of the frontend will make gradle order them as needed.
You can browse this project of mine to have an example using basically the same setup (except it uses yarn instead of npm to resolve dependencies)
Answer of JB Nizet should work. You can also add the following in the root gradle file:
build.dependsOn("core:build").mustRunAfter("ui:build")
Above answer is in my opinion cleaner.
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
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.
I'm using Gradle and Spring Boot for the first time. I decided to create a project that actually builds a WAR archive and I'm using the Gradle Jetty plugin. If I run the jettyRun or jettyRunWar tasks, in my browser all I'm seeing is a directory listing, not my actual application.
For example, the jettyRunWar task results in a directory listing like this:
META-INF/
WEB-INF/
dist/
The dist/ directory contains my static files.
Maybe I'm missing something fundamental since I'm using Gradle and Spring Boot for the first time.
I'm trying to test my app while making changes to my static files without restarting the app. Here is my build.gradle file.
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:0.5.0.M6"
}
}
apply plugin: "java"
apply plugin: "idea"
apply plugin: "spring-boot"
apply plugin: "war"
war {
baseName = "mis-support-client"
version = "1.0.0-SNAPSHOT"
includes = ["dist/**"]
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}
dependencies {
testCompile "junit:junit:4.11"
compile ("org.springframework.boot:spring-boot-starter-web:0.5.0.M7") {
exclude module: "spring-boot-starter-tomcat"
}
compile "org.springframework.boot:spring-boot-starter-jetty:0.5.0.M7"
compile "org.springframework.boot:spring-boot-starter-security:0.5.0.M7"
compile "org.springframework.boot:spring-boot-starter-websocket:0.5.0.M7"
compile "javax.inject:javax.inject:1"
compile "org.codehaus.jackson:jackson-mapper-asl:1.9.12"
compile "org.apache.httpcomponents:httpclient:4.3.1"
compile "commons-io:commons-io:2.4"
}
task wrapper (type: Wrapper) {
gradleVersion = "1.8"
}
Did you try ./gradlew bootRun instead? Normal Spring Boot project has server embedded for easier usage :)
This task requires gradle plugin:
apply plugin: 'spring-boot'
Features
Embed Tomcat or Jetty directly (no need to deploy WAR files)
Task
Execution tasks
---------------
bootRun - Run the executable JAR/WAR