Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value of a manifest attribute must not be null (Key=Start-Class #10621

Closed
bodiam opened this issue Oct 12, 2017 · 6 comments
Closed

The value of a manifest attribute must not be null (Key=Start-Class #10621

bodiam opened this issue Oct 12, 2017 · 6 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@bodiam
Copy link

bodiam commented Oct 12, 2017

kotlinVersion = '1.1.51'
springBootVersion = '2.0.0.M5'
javaVersion = '9'
gradleVersion = 4.2.1

Bug report

Running a ./gradlew clean build results in the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootJar'.
> The value of a manifest attribute must not be null (Key=Start-Class).

For a simple project to reproduce: https://github.com/bodiam/booklist

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 12, 2017
@bodiam
Copy link
Author

bodiam commented Oct 12, 2017

I tried fixing it by adding

bootRun {
	main = 'com.booklist.backend.BackendApplication'
}

To the build.gradle file, but no effect.

@wilkinsona
Copy link
Member

wilkinsona commented Oct 12, 2017

I think your main method is declared at the wrong level. I believe it should be:

diff --git a/src/main/kotlin/com/booklist/backend/BackendApplication.kt b/src/main/kotlin/com/booklist/backend/BackendApplication.kt
index f6efae2..bea523b 100644
--- a/src/main/kotlin/com/booklist/backend/BackendApplication.kt
+++ b/src/main/kotlin/com/booklist/backend/BackendApplication.kt
@@ -16,16 +16,15 @@ import javax.persistence.Id
 @SpringBootApplication
 class BackendApplication {

-    fun main(args: Array<String>) {
-        SpringApplication.run(BackendApplication::class.java, *args)
-    }
-
     @Bean
     fun startup(userService: UserService) = CommandLineRunner {
         userService.register("erik", "erik@gmail.com")
     }

+}

+fun main(args: Array<String>) {
+    SpringApplication.run(BackendApplication::class.java, *args)
 }

 @RestController

With this change in place I can build the fat jar and run it with java -jar.

And, just for the record, setting main on bootRun had no effect as it was the bootJar task that was failing.

@wilkinsona
Copy link
Member

I should also have said that I defer to @sdeleuze for all things Kotlin, and the change I've proposed above brings things into line with the main class in his Spring Boot Kotlin demo.

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 12, 2017
@bodiam
Copy link
Author

bodiam commented Oct 12, 2017

Hi @wilkinsona , thanks for that, you're right! I've checked it, just to be sure, with Josh' app here: https://github.com/joshlong/flux-flix-service/blob/master/kotlin/flux-flix-service/src/main/kotlin/com/example/fluxflixservice/FluxFlixServiceApplication.kt, and same. Cheers!

@sdeleuze
Copy link
Contributor

sdeleuze commented Oct 13, 2017

Yeah that's the setup I recommend and that we use on our examples and on start.spring.io.

As an alternative, it is possible to declare the main() method inside the application class, but but you would have to use this no very nice syntax to make it a Java static method:

@SpringBootApplication
class BackendApplication {

    companion object {
        @JvmStatic fun main(args: Array<String>) {
            SpringApplication.run(BackendApplication::class.java, *args)
        }
    }

     @Bean
     fun startup(userService: UserService) = CommandLineRunner {
         userService.register("erik", "erik@gmail.com")
     }
}

So probably better to use top level main() method everywhere.

Also see #10511 which will provide an even better syntax in 2.0.0.M6.

@bodiam
Copy link
Author

bodiam commented Oct 14, 2017

Ah, thanks for that, I'll have a look at #10511 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants