简体   繁体   中英

Spring boot custom starter thru Gradle

Any tutorial I found online, creates a custom spring boot starter thru Maven. Is there a way to create it using Gradle?

I tried to use gradle. It successfully creates a jar file for me. The condition is that I must have a main class. That's a problem I assume as any online tutorial I found that creates custom starter does not have a main method in them.

2nd issue is that the jar file that it produces, which works perfectly fine when run from cmd like this java -jar jarname.jar , has a directory structure where my custom configurations are not at the root. It has spring boot related stuff at the root. I am sure I need my classes to be at the root of the jar file.

Hence my question, how do I create a custom starter project thru gradle?

It sounds like you have applied Spring Boot's Gradle plugin. If you are building a starter – a reusable library – you should not do that. Instead, you should only apply Gradle's java or java-library plugins.

You may want to use Boot's dependency management when building your starter. You can do that by referencing Boot's Gradle plugin but not applying it and importing its bom :

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE' apply false
}

dependencyManagement {
    imports {
        mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM