I have a problem with deploying gradle project to heroku.
Here is my gradle.build file
plugins {
id 'java'
id 'distribution'
}
group 'com.artek.ej_bot'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
compile files(fileTree(dir: 'libs', includes: ['*.jar']))
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
task stage {
dependsOn installDist
}
And I keep getting this error:
It looks like your project does not contain a 'stage' task, which Heroku needs in order to build your app
I run this command heroku config:set GRADLE_TASK="build" in terminal and deploy became successful
here's how I have setup the stage task for my gradle project deployed on Heroku
task stage(type: Copy, dependsOn: ['build', 'clean', 'shadowJar']) {
from 'build/libs/app-0.0.1.jar'
into project.rootDir
rename {
'app.jar'
}
}
stage.mustRunAfter(clean)
Related
I have a GRADLE application which has the following structure:
It has some dependencies as well (can see it from the image above)
I have built it using ./gradlew clean build
I am trying to run the following from the terminal java -jar build/libs/script-application-1.0-SNAPSHOT.jar which is throwing no main manifest attribute, in script-application-1.0-SNAPSHOT.jar
I have the following in build.gradle
plugins {
id 'java'
}
jar {
manifest {
attributes(
'Main-Class': 'Application'
)
}
}
group 'ScriptApplication'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9.3'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
}
Please help. How can I run the jar from terminal? The next step is to run the jar from a remote server.
Edit:
Followed the suggestion from the comment and updated my build.gradle. But I still don't understand where will the jar get generated and how will I run the jar?
plugins {
id 'java'
}
group 'ScriptApplication'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9.3'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
}
task fatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'Application'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Had to add:
task fatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'Application'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Then run gradle clean and gradle fatJar.
Then one can run the jar by:
java -jar build/libs/<application>.jar
After create a new Java EE project - in IntelliJ - new project -> Gradle from left list -> next -> next
I fill 2 files
build.gradle:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
group 'com.random'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
providedCompile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
and
#Path("/reservation")
public class ReservationWebService {
#GET
public Response listReservations() {
return Response.ok("hello").build();
}
}
now I'm trying to generate war by:
gradle war in terminal and I got:
'gradle' is not recognized as an internal or external command,
operable program or batch file.
How to generate war ?
I have java project with gradle and spring boot that I want to deploy to Heroku.
I created myApp.war locally using gradle war (I have to deploy locally because I'm using a local lib repository). The war have been created with success, but when I tried to deploy to Heroku heroku war:deploy myApp.war --app appName, I received the error:
! ERROR: Your buildpacks do not contain the heroku/jvm buildpack!Add heroku/jvm to your buildpack configuration or run `heroku buildpacks:clear`.
! Re-run with HEROKU_DEBUG=1 for more info.
! There was a problem deploying to appName.
! Make sure you have permission to deploy by running: heroku apps:info -a appName
I'm using:
Java 10
Spring boot
Gradle 4
I have already add heroku/gradle build pack trough the heroku app settings.
build.gradle
plugins {
id 'java'
id 'idea'
id 'maven'
id 'war'
id 'application'
id 'org.springframework.boot' version '2.0.6.RELEASE'
}
mainClassName = "com.my.app.BootApplication"
war {
baseName = 'my-app'
version = '1.0.0'
}
logger.lifecycle "war.archivePath = $war.archivePath"
description = """My app description"""
sourceCompatibility = 10
targetCompatibility = 10
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
maven { url uri('../my-locally-private-repository') }
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web-services', version:'2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version:'2.0.4.RELEASE'
compile 'com.github.jsimone:webapp-runner:8.5.11.3'
compile group: 'org.hamcrest', name: 'hamcrest-core', version:'1.3'
compile group: 'com.my.app, name: 'private-dependency-1', version:'1.0.0'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'2.0.4.RELEASE'
}
system.properties
java.runtime.version=10
Procfile
web: java -jar build/server/webapp-runner-.jar build/libs/.war
How can I solve this problem?
Run heroku buildpacks:clear like the error message says. The heroku/gradle buildpack is not used when you push a WAR file.
I am trying to execute a Grizzly HTTP Server inside a container.
Why i have this error, while running jar:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/grizzly/http/server/HttpServer
All was allright in maven with pom, but i met this error in gradle.
This is my build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.13.0",
}
}
group 'com.mycompany'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.palantir.docker'
docker {
name "${project.group}/${jar.baseName}"
files 'build/libs'
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
jar {
manifest {
attributes 'Main-Class': 'com.mycompany.json_validator.Main'
}
baseName = 'JSON_validator-boot-docker'
version = '0.2.0'
archiveName = 'JSON_validator-boot-docker-0.2.0.jar'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.26'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '2.7'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.17'
compile group: 'org.glassfish.jersey', name: 'jersey-bom', version: '2.17', ext: 'pom'
}
All in all, i want to build jar for docker.
java.lang.NoClassDefFoundError:
org/glassfish/grizzly/http/server/HttpServer
NoClassDefFoundError indicates definition of the class could be found at the runtime, this could be missing jar/libraries. Make sure, you have included grizzly-http-server-x.x.x.jar and related jars in classpath.
I'm trying to build a Java Servlet with gradle gretty plugin (gradle version 3.4).
I have a dependency to another project databaseprovider:1.0-SNAPSHOT (includes connection to the database and some spring definitions...).
When I run the task "gradle war" the .war-file is built properly with all dependencies in WEB-INF/lib.
But when I try to start with "gradle appStart" I have following problem:
What went wrong: Execution failed for task ':appStart'. Could not get
unknown property 'classesDirs' for main classes of type
org.gradle.api.internal.tasks.DefaultSourceSetOutput.
Caused by: groovy.lang.MissingPropertyException: Could not get unknown
property 'classesDirs' for main classes of type
org.gradle.api.internal.tasks.DefaultSourceSetOutput.
Without the dependency databaseprovider:1.0-SNAPSHOT the jetty starts without problems:
INFO Jetty 9.2.22.v20170606 started and listening on port 8080
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.akhikhl.gretty:gretty:+"
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE"
}
}
apply plugin:'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
repositories {
maven {
url "http://..."
}
mavenLocal()
}
dependencies {
compile('databaseprovider:1.0-SNAPSHOT'){
changing=true
}
}
gretty {
httpPort = 8080
contextPath = '/'
servletContainer = 'jetty9'
}
build.gradle from databaseprovider:
buildscript {
repositories {
maven {
url "http://..."
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply from: 'liquibase.gradle'
jar {
baseName = 'databaseprovider'
version = '1.0-SNAPSHOT'
}
repositories {
maven {
url "http://..."
}
mavenLocal()
jcenter()
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.4.0.RELEASE")
compile group: 'org.springframework.data', name: 'spring-data-jpa', version:'1.10.2.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.0.9.Final'
testRuntime group: 'com.h2database', name: 'h2', version: '1.4.192'
compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.0.13'
compile group: 'ch.qos.logback', name: 'logback-core', version:'1.0.13'
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.5'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version:'1.7.5'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version:'1.7.5'
compile group: 'org.reflections', name: 'reflections', version: '0.9.11'
compile (group: 'com.mattbertolini', name: 'liquibase-slf4j', version: "1.2.1")
compile (group: 'org.liquibase', name: 'liquibase-core', version: "3.5.3")
compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'
testCompile("junit:junit")
runtime("mysql:mysql-connector-java:5.1.39")
testCompile("org.springframework:spring-test")
}
I was able to solve the problem by adding the version of gretty:
After I changed the classpath in build.gradle
classpath "org.akhikhl.gretty:gretty:+"
to
classpath "org.akhikhl.gretty:gretty:1.4.2"
(compatible version to gradle 3.4) jetty starts without exceptions.
I found this question by googling for the error message when I encountered this issue. For me, I found my answer in this Github thread. Basically, by upgrading my version of Gradle to 4.8 I was able to resolve the issue.