Deploy my Gradle (Spring Boot) app in Heroku - heroku

I have a gradle + spring boot application with the following build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
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: 'org.springframework.boot'
jar {
baseName = 'teambuilting'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
But, when I am trying to deploy my master branch in Heroku, I get the following error:
-----> Failed to detect set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/gradle.tgz
More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
! Push failed
I added in the Buildpacks, heroku/gradle. What else am I missing?

you have to define in the dashboard that the project use the buildpack for Gradle. In the build.gradle, has to add this task:
task stage {
dependsOn build
}
and create a Procfile to indicate the next steps once heroku build your software.
Juan Antonio

Related

unable to run the springboot jar from command line

My requirement is to build a spring boot jar in standalone tomcat executable.I am not able to run the jar from command line.
I am using gradle
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile project(':testProject')
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
}
jar {
manifest {
attributes 'Implementation-Title': 'SpringAppApplication',
'Implementation-Version': version
}
}
running java -jar target/SpringAppApplication-0.0.1-SNAPSHOT.jar
I get error Invalid or corrupt jarfile SpringApp-0.0.1-SNAPSHOT.jar
.Tried giving the complete path also.

org.springframework.boot.context.embedded does not exist - Gradle build Spring Boot Jetty

I am trying to replace Tomcat with Jetty, as my embedded servlet container. And then need to use EmbeddedServletContainerCustomizer() to configure redirecting requests at port 80 to port 443 (HTTPS). But I am stuck at the very beginning with these gradlew build errors:
RedirectHttpToHttpsOnJettyConfig.java:7: error: package org.springframework.boot.context.embedded does not exist
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
RedirectHttpToHttpsOnJettyConfig.java:8: error: package org.springframework.boot.context.embedded does not exist
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
RedirectHttpToHttpsOnJettyConfig.java:9: error: package org.springframework.boot.context.embedded.jetty does not exist
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
RedirectHttpToHttpsOnJettyConfig.java:10: error: package org.springframework.boot.context.embedded.jetty does not exist
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer;
...
Here's my build.gradle:
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
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: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
ext['thymeleaf.version'] = '3.0.9.RELEASE'
war {
baseName = 'reachout'
version = '0.0.2'
}
compileJava {
options.warnings = true
options.debug = true
options.compilerArgs += ["-Xlint:deprecation"]
}
sourceSets {
main {
java {
exclude '**/RedirectHttpToHttpsOnTomcatConfig.java'
}
}
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4')
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
Any pointers are much appreciated.
Duplicate. See
Spring Boot 2.0.0.M1: Where is the package org.springframework.boot.context.embed?
Here is the relevant spring commit
https://github.com/spring-projects/spring-boot/commit/67556ba8eaf22a352b03fe197a0c452f695835a6

How do I create an an executable jar in Spring Boot?

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

How to use Gradle with Spring Boot to get Gosling Release Train of Spring data?

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.

Spring Batch with Grails

im currently using grails 3.0.3 along with gradle 2.5 and hoping to generate a plugin that will use Spring Batch. I've just created a plugin via the command line, and update the build.gradle with just the
compile "org.springframework.boot:spring-boot-starter-batch"
However the batch folder does not seem to downloaded to the local .m2 cache and therefore the import org.springframework.batch libs not available.
The following is the build.gradle. Just wondering if anybody could suggest the reasons why?
Thanks
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
id "com.jfrog.bintray" version "1.2"
}
version "0.1-SNAPSHOT"
group "org.grails.plugins"
apply plugin: 'maven-publish'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "spring-boot"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"
// Used for publishing to central repository, remove if not needed
apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/grailsCentralPublishing.gradle'
apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/bintrayPublishing.gradle'
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"
provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'
testCompile "org.grails:grails-plugin-testing"
console "org.grails:grails-console"
//compile "org.springframework.boot:spring-boot-starter-batch:1.2.5.RELEASE"
compile "org.springframework.boot:spring-boot-starter-batch"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}

Resources