Our application is currently running on spring boot 1.5.10.RELEASE version, and I'm trying to upgrade to spring boot 2.0.0.RELEASE But after upgrading to 2.0.0.RELEASE I get the following error
Error: Could not find or load main class com.app.MyApplication
Given Below is the build.gradle file
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
camelVersion = '2.24.0'
}
repositories {
mavenCentral()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
apply from: '../common.gradle'
apply from: '../test.gradle'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'io.spring.dependency-management'
dependencies {
providedRuntime "org.springframework.boot:spring-boot-starter-tomcat"
compile ("org.flywaydb:flyway-core:5.0.7")
compile ("org.springframework.retry:spring-retry:1.2.2.RELEASE")
compile("org.springframework:spring-jms:5.1.1.RELEASE")
compile("org.springframework.boot:spring-boot-starter-activemq:2.0.6.RELEASE")
compile("org.springframework:spring-jdbc:5.0.4.RELEASE")
compile("org.springframework.retry:spring-retry:1.2.2.RELEASE")
compile("com.amazonaws:aws-java-sdk-sqs:1.11.428")
compile("com.amazonaws:amazon-sqs-java-messaging-lib:1.0.4")
compile ("org.flywaydb:flyway-core:5.0.7")
runtime("org.apache.activemq:activemq-kahadb-store:5.15.6")
compile("org.apache.camel:camel-spring-boot-starter:${camelVersion}")
compile("org.apache.camel:camel-core:${camelVersion}")
compile("org.apache.camel:camel-http-starter:${camelVersion}")
compile("org.apache.camel:camel-http4:${camelVersion}")
compile("org.apache.camel:camel-jsonpath:${camelVersion}")
compile("org.apache.camel:camel-jackson:${camelVersion}")
compile("org.apache.camel:camel-base64:${camelVersion}")
compile("org.apache.camel:camel-groovy:${camelVersion}")
compile("org.apache.camel:camel-jolt:${camelVersion}")
compile("org.apache.camel:camel-jaxb:${camelVersion}")
compile("org.apache.camel:camel-ahc:${camelVersion}")
compile("org.codehaus.groovy:groovy-json:3.0.3")
}
configurations {
all*.exclude group: '', module: 'servlet-api'
}
springBoot {
mainClassName = 'com.app.MyApplication'
}
war {
archiveName = "application.war"
}
I'm wondering if this is due to the camel dependencies as when I tried to use Spring Boot version 1.5.22. It is working fine but as soon as I change this to 2.x.x it stop working.
This issue got resolved when I ran this application in Intellij instead of the eclipse.
Related
I have a Spring MVC project using Spring Boot 1.5.2 with Gradle Buildship in Spring Tool Suite.
How do I create a JAR file from my source only which will run in another server and download the required dependencies there?
How do I create a fat JAR with all of the source files and the dependencies?
My gradle.build file is:
buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
mainClassName = "com.jtv.elastic.mvc.ElasticSpringApplication"
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
You should use bootRepackage task for gradle. More information here and here
I've created a fresh new Spring Boot 1.5.1.RELEASE project with a devtools dependency:
dependencies {
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
When running from inside Idea this works no problem. However, after performing a bootRepackage, the resulting fat jar has no devtools jar in its lib folder. I have the following entry in build.gradle:
bootRepackage {
mainClass = 'com.example.HotreloadApplication'
excludeDevtools = false
}
And upon a ./gradlew bootRepackage and a java -jar build/libs/hotreload-0.0.1-SNAPSHOT.jar, I can see that it fires up without devtools still. Upon opening the jar, I can also see that it is not included.
When moving springBootVersion back to '1.4.4.RELEASE' howeverm everything works absolutely as expected.
Any help would be greatly appreciated! I've included the entirety of my build.gradle following this message.
Many thanks,
Duncan
----- build.gradle ----
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'hotreload'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
bootRepackage {
mainClass = 'com.example.HotreloadApplication'
excludeDevtools = false
}
This question is superseded by this issue on the Spring Boot tracker that the author has cross-posted.
That's correct, thanks Stephane. A workaround is posted on the github ticket, by adding the following block to build.gradle:
springBoot {
excludeDevtools = false
}
With any luck, this bug should be fixed in 1.5.2.
Many thanks,
Duncan
I have a Gradle setup where I currently need to hard code the spring-boot version. Is it possible to do this with dependency management instead? The issue occurs in my project module that contains the actual code. There I need a call to :
springBoot {
requiresUnpack = ["com.example:util"]
}
In order to do that I need to apply the spring-boot plugin. For that plugin to be available I need to have a dependency to "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}". And for that I need to specify the springBootVersion hard coded...
This is my parent gradle file:
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath 'io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE'
}
}
plugins {
id "io.spring.dependency-management" version "0.6.0.RELEASE"
}
group 'test'
repositories {
mavenCentral()
}
allprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
// Note that these two BOM's are not always easy to combine, always define cloud first and try to find versions with same version of spring-boot when upgrading.
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR5'
mavenBom 'io.spring.platform:platform-bom:2.0.7.RELEASE'
}
}
}
and this is my module gradle file:
group = "test"
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
// Temporary fix for jersey
springBoot {
requiresUnpack = ["com.example:util"]
}
If I remove the dependency to spring-boot-gradle-plugin in parent gradle file, then I cannot use the apply plugin: 'spring-boot' in the module gradle file and without that the gradle DLS method springBoot { is not defined...
Can I achieve this without having to hard code springBootVersion = '1.4.0.RELEASE'in my parent gradle file?
How can I get the latest Gosling release train into my Gradle build file?
I used to be using the 1.1.9.RELEASE group for most of my dependencies. Now I need to fix the problem with RepositoryRestMvcConfiguration mentioned here and to do so I am trying to upgrade to the latest release of spring Data, which has fixed the bug according to the github issue I linked to.
When I added the Gosling release train dependencies I also removed the spring boot starters for spring-data-jpa and spring-data-rest thinking I might have dependency conflicts. Doing this pulled in the new jar files but now I am getting cannot find symbol errors on all my javax.persistence annotations.
Can I use the Gosling release train with the spring boot starters or do I have to figure out how to pull in all spring boot dependencies manually in order to use Gosling?
I am using Gradle 2.3.10 on Mac OS X Yosemite.
New Code
buildscript {
ext {
springBootVersion = '1.3.0.M3'
}
repositories {
jcenter()
mavenCentral()
//maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE"
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: "io.spring.dependency-management"
ext {
springVersion = '4.1.6.RELEASE'
springDataVersion = 'Gosling-RELEASE'
}
dependencyManagement {
imports {
mavenBom "org.springframework:spring-framework-bom:${springVersion}"
mavenBom "org.springframework.data:spring-data-releasetrain:${springDataVersion}"
}
}
jar {
baseName = 'my-data-api'
version = '0.0.1'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
//maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator:1.3.0.M3")
compile("org.springframework.boot:spring-boot-starter-aop:1.3.0.M3")
compile 'org.springframework.data:spring-data-jpa'
compile 'org.springframework.data:spring-data-rest-webmvc'
compile("org.springframework.boot:spring-boot-starter-web:1.3.0.M3")
compile("org.springframework.boot:spring-boot-starter-jdbc:1.3.0.M3")
compile('org.antlr:stringtemplate:4.0.2')
compile('org.apache.commons:commons-lang3:3.0')
compile('commons-io:commons-io:2.4')
compile('com.ingres.jdbc:iijdbc:10.0-4.0.5')
testCompile("org.springframework.boot:spring-boot-starter-test:1.3.0.M3")
}
Old code
buildscript {
ext {
springBootVersion = '1.3.0.M2'
}
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'my-data-api'
version = '0.0.1'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator:1.2.0.RC2")
compile("org.springframework.boot:spring-boot-starter-aop:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-web:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-data-rest:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-jdbc:1.1.9.RELEASE")
compile('org.antlr:stringtemplate:4.0.2')
compile('org.apache.commons:commons-lang3:3.0')
compile('commons-io:commons-io:2.4')
compile('com.ingres.jdbc:iijdbc:10.0-4.0.5')
testCompile("org.springframework.boot:spring-boot-starter-test:1.1.9.RELEASE")
}
Edit:
If I put a javax persistence dependency in my build.gradle then I can successfully build and use RepositoryRestConfigurerAdapter, but I get runtime problems with dependencies missing for my entityManagerFactory
If you are already using milestone versions of Spring Boot, I suggest you switch to M5. It includes Gosling-RELEASE Spring Data.
Replacing a persistence layer in legacy app with a JAR file using Spring, Hibernate and GORM. Methods like person.save() work fine when running agains project with Gradle etc. in project. However, after I build the fat jar and reference it with -cp my-big-fat-gorm.jar I get:
java.lang.IllegalStateException: Method on class [blah.Person] was
used outside of a Grails application. If running in the context of a
test using the mocking API or bootstrap Grails correctly.
Using Spring boot for Spring, Hibernate4 and GORM and build.gradle file show below...
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'application'
mainClassName = "blah.App"
jar {
baseName = 'blah-gorm'
version = '1.0-SNAPSHOT'
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.8.2'
compile 'org.grails:gorm-hibernate4-spring-boot:1.1.0.RELEASE'
compile 'org.slf4j:slf4j-simple:1.7.7'
runtime 'com.h2database:h2:1.4.181'
}
Am I missing something in the JAR file creation that causes Spring boot to honor #Entity etc.?
Here is a GitHub project that illustrates this and should allow you to execute and see the same stuff I'm seeing.
https://github.com/twcrone/spring-gorm-jar
You don't have the Spring Boot Gradle plugin installed so you're not actually creating a fat JAR you need to add the following to your build.gradle file:
apply plugin: 'spring-boot'
buildscript {
ext {
springBootVersion = '1.1.0.M2'
groovyVersion = '2.3.2'
}
repositories {
mavenCentral()
maven {
url 'http://repo.spring.io/milestone'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
With this in place doing gradle assemble and then java -jar ... results in bootstrapping GORM correctly