I have a Spring boot gradle project built using IntelliJIDEA with gradle.build:
plugins {
id 'org.springframework.boot' version '2.5.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'pk.inlab.app.web'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
// Apache commons
implementation 'commons-beanutils:commons-beanutils:1.9.4'
// Jwt
implementation 'io.jsonwebtoken:jjwt:0.9.1'
// OpenAPI and Swagger
implementation 'org.springdoc:springdoc-openapi-ui:1.5.11'
implementation 'org.springdoc:springdoc-openapi-data-rest:1.5.11'
// Passy
implementation 'org.passay:passay:1.6.1'
// Thymeleaf for registration email with template
implementation 'org.thymeleaf:thymeleaf-spring5'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
// Rest Assured
testImplementation 'io.rest-assured:spring-mock-mvc:4.4.0'
// hamcrest-library
testImplementation 'org.hamcrest:hamcrest-library:2.2'
}
test {
useJUnitPlatform()
}
the project works well on local machine, when pushed to bitbucket with pipeline setting file bitbucket-pipelines.yml:
# Template Java Gradle build
# This template allows you to test and build your Java project with Gradle.
# The workflow allows running tests, code checkstyle and security scans on the default branch.
# Prerequisites: appropriate project structure should exist in the repository.
image: gradle:7.2
pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- gradle
script:
- gradle clean build
- git archive --format=tar.gz master -o application.tar.gz
- pipe: atlassian/heroku-deploy:1.2.1
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_NAME
ZIP_FILE : "application.tar.gz"
after-script:
- pipe: atlassian/checkstyle-report:0.2.0
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.4.3
the build logs are all correct, it shows:
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/gradle
-----> Gradle app detected
-----> Spring Boot detected
-----> Installing JDK 1.8... done
-----> Building Gradle app...
-----> executing ./gradlew build -x check
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.2/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJarMainClassName
> Task :bootJar
> Task :jar
> Task :assemble
> Task :build
BUILD SUCCESSFUL in 20s
5 actionable tasks: 5 executed
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 99.4M
-----> Launching...
Released v8
https://rest-todo-work.herokuapp.com/ deployed to Heroku
after all when I visit the site its shows:
when I check heroku logs it shows:
2021-10-26T04:35:07.000000+00:00 app[api]: Build started by user superuseremail@gmail.com
2021-10-26T04:35:46.654664+00:00 app[api]: Release v8 created by user superuseremail@gmail.com
2021-10-26T04:35:46.654664+00:00 app[api]: Deploy cf272d57 by user superuseremail@gmail.com
2021-10-26T04:35:46.918113+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-26T04:35:50.193127+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=37836 $JAVA_OPTS -jar build/libs/*.jar`
2021-10-26T04:35:50.877195+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2021-10-26T04:35:50.890431+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-10-26T04:35:50.894017+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-10-26T04:35:50.954182+00:00 app[web.1]: no main manifest attribute, in build/libs/to-do-0.0.1-SNAPSHOT-plain.jar
2021-10-26T04:35:51.082759+00:00 heroku[web.1]: Process exited with status 1
2021-10-26T04:35:51.148321+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-26T04:36:03.000000+00:00 app[api]: Build succeeded
2021-10-26T04:39:01.736780+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=rest-todo-work.herokuapp.com request_id=21a8013c-0771-4758-8245-a575145bc3b0 fwd="111.119.183.2" dyno= connect= service= status=503 bytes= protocol=https
2021-10-26T04:39:02.249498+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=rest-todo-work.herokuapp.com request_id=7fd63420-a032-49ef-bd81-990df93bc5d1 fwd="111.119.183.2" dyno= connect= service= status=503 bytes= protocol=https
all right when I wanted to solve no main manifest attribute,
I found a SO post which suggests to add:
jar {
manifest {
attributes 'Main-Class': 'pk.inlab.app.web.todo.ToDoApplication'
}
}
in gradle file, I added and heroku logs are:
2021-10-26T04:28:04.396482+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-26T04:28:07.756486+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=45162 $JAVA_OPTS -jar build/libs/*.jar`
2021-10-26T04:28:09.250355+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2021-10-26T04:28:09.274928+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-10-26T04:28:09.278725+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-10-26T04:28:09.420855+00:00 app[web.1]: Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
2021-10-26T04:28:09.420930+00:00 app[web.1]: at pk.inlab.app.web.todo.ToDoApplication.main(ToDoApplication.java:12)
2021-10-26T04:28:09.420987+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
2021-10-26T04:28:09.421018+00:00 app[web.1]: at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
2021-10-26T04:28:09.421046+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
2021-10-26T04:28:09.421075+00:00 app[web.1]: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
2021-10-26T04:28:09.421102+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
2021-10-26T04:28:09.421129+00:00 app[web.1]: ... 1 more
2021-10-26T04:28:09.609559+00:00 heroku[web.1]: Process exited with status 1
this adds a new error. Any suggestions for these issues.