1
votes

I'm trying to build a library. I have Spring Boot Gradle Plugin in my build.gradle file:

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

My library without the main class. To prevent 'Main class not configured ...' error I add to build.gradle:

bootRepackage {
enabled = false
}

but got an error:

A problem occurred evaluating root project 'mysuperlibrary'.

Could not find method bootRepackage() for arguments [build_3886uiniuyuorta9lpa9n4f5c$_run_closure3@1975ec48] on root project 'mysuperlibrary' of type org.gradle.api.Project.

All works fine with Spring boot Gradle Plugin 1.5.16 but don't works with 2.1.3.

UPDATE: This plugin I use because without it I can`t resolve testCompile 'org.springframework.boot:spring-boot-starter-test' . When I delete the plugin I can build project bit dependency for test disappears.

3
You can use this line in build.gradle: apply plugin: 'java-library'. Spring Boot Plugin automatically will not create start up class for output jar. Also, plugin will still control dependencies from this sub-project.Mister_Jesus

3 Answers

5
votes

Now I'm using spring plugin with 2.1.* version in all my libs. It is necessary to add next before 'dependencies' section:

bootJar {
    enabled = false
}

jar {
    enabled = true
}
1
votes

Update:

Just remove the plugin and add the testing dependencies directly. E.g. with JUnit 5:

dependencies {
      testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.1'
      ....
      testImplementation(
            "org.junit.jupiter:junit-jupiter-api:$jUnitVersion",
            "org.junit.jupiter:junit-jupiter-params:$jUnitVersion"
      )
      testRuntimeOnly(
              "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
      )
      test {
          useJUnitPlatform()
      }
}

Old (suited for multi modul project): You can use the apply flag:

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

and write a function

def isAbstract(project) {
    return ['mysuperlibrary'].contains(project.name)
}

subprojects { project ->
    if (isAbstract(project) {
        return
    }

    apply plugin: 'org.springframework.boot'

}
1
votes

May be like this:

tasks {
    bootJar { mainClassName = "NONE" }
}