1

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.

Valeriy K.
  • 2,616
  • 1
  • 30
  • 53
  • 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 Dec 24 '19 at 11:42

3 Answers3

5

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
}
Valeriy K.
  • 2,616
  • 1
  • 30
  • 53
1

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'

}
Chris
  • 5,109
  • 3
  • 19
  • 40
  • I think the second code doesn't have sense, because I use it in my "mysuperlibrary". Yes, I build the project, but I can do the same by deleting the plugin. I didn't say that this plugin I use because without it I can`t resolve testCompile 'org.springframework.boot:spring-boot-starter-test' . When I delete the plugin, dependency for test disappears. – Valeriy K. Sep 03 '19 at 12:54
  • Ah sorry, I thought you are having a multi module project. Then just add the dependencies you need directly. Like `testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.1'` Why would you use the spring-boot-starter-test dependency, when the whole project isn't a springboot application. I updated my answer. – Chris Sep 03 '19 at 13:28
  • 1
    I solved my problem when explicitly specified test dependency: testCompile 'org.springframework.boot:spring-boot-starter-test:2.1.7.RELEASE' . I removed the plugin also. Your answer was not exactly what I wanted, but was very useful. Thanks. – Valeriy K. Sep 03 '19 at 13:40
1

May be like this:

tasks {
    bootJar { mainClassName = "NONE" }
}
Dmitry Kaltovich
  • 2,046
  • 19
  • 21