`I am encountering an issue while attempting to deploy my application in Railway. Locally, the application runs without any problems. However, during the deployment process in Railway, I keep encountering the following error message:
no main manifest attribute, in build/libs/12WeekMethod-plain.jar
This is my build.gradle:
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.mundim'
version = ''
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-maven-plugin:3.1.1'
implementation 'org.testng:testng:7.1.0'
runtimeOnly 'org.postgresql:postgresql'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Swagger
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
// Security
implementation 'org.springframework.boot:spring-boot-starter-security:3.1.1'
// Thymeleaf
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.1.1.RELEASE'
// JJWT
implementation 'com.auth0:java-jwt:4.2.1'
// Mail sender
implementation 'org.springframework.boot:spring-boot-starter-mail'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// Thymeleaf
implementation 'org.thymeleaf:thymeleaf:3.1.1.RELEASE'
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.h2database:h2:2.2.220'
testImplementation 'junit:junit:4.13.2'
}
tasks.named('test') {
useJUnitPlatform()
}
The problem is your dependencies are a mess. You are including incompatible versions and are mixing modules from different versions of a framework. Here you are mixing Spring Boot 2.7.x and 3.1.x that is never going to work nor is something you should never do.
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.mundim'
version = ''
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
runtimeOnly 'org.postgresql:postgresql'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Swagger
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
// JJWT
implementation 'com.auth0:java-jwt:4.2.1'
// Mail sender
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.h2database:h2:2.2.220'
}
tasks.named('test') {
useJUnitPlatform()
}
testng
and junit
dependency as you seem to be using JUnit Jupiter (judging from the test setup).spring-boot-starter-*
dependencies so the versions alignorg.thymeleaf.extras:thymeleaf-extras-springsecurity5
so it uses a compatible version (managed by Spring Boot)spring-boot-starter-thymeleaf
to get the proper version and management.With this you should have proper and compatible versions and your application will start.
Finally you should use ./gradlew build
to build a jar and not use the plain
one as that doesn't include the dpendencies. You need to deploy the fatjar created by Spring Boot.