找不到不需要的 mainClassName

mainClassName not found which is not needed

我正在创建一个根本没有主 class 的库。该库使用 Spring,它有正在寻找 mainClassName 的应用程序插件。我添加了带有 null 的 mainClassName,但我正在寻找更好的解决方案。我四处搜索,发现添加 bootJar.enabled = false 不会查找 mainClassName 但它没有帮助。有人可以帮我吗?

    ext {
        springBootVersion = '2.2.1.RELEASE'
        satelliteVersion = '2.12.3'
    }

    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath('org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE') {
            exclude group: 'org.slf4j'
            exclude module: 'spring-boot-starter-log4j'
        }
    }
}

plugins {
    id 'java'
    id 'groovy'
    id 'idea'
    id 'distribution'
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

repositories {
    mavenLocal()
    mavenCentral()
}
bootJar.enabled = false
apply plugin: 'maven-publish'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
version = System.getenv('CI') == 'drone' ? "1.0.${System.getenv('DRONE_BUILD_NUMBER')}" : "local"
tasks.validateYaml.enabled = false

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-mail:${springBootVersion}"

    implementation group: 'com.google.guava', name: 'guava', version: '18.0'
    implementation group: 'commons-io', name: 'commons-io', version: '2.6'

}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact tasks.sourcesJar
        }
    }
}
configurations.all {
    exclude module: 'spring-boot-starter-logging'
    exclude group: 'ch.qos.logback'
    exclude module: 'logback-access-spring-boot-starter'

}

我收到以下错误

A problem was found with the configuration of task ':startScripts' (type 'CreateStartScripts').
> No value has been specified for property 'mainClassName'.


添加

startScripts.enabled = false
bootJar.enabled = false
distTar.enabled = false

解决了我的issue.Thanks

想在 2022 年添加我的答案,因为已接受的答案对我不起作用。然而,删除 spring boot 插件可以解决问题。

// id 'org.springframework.boot' version '2.6.1'
// id 'io.spring.dependency-management' version '1.0.11.RELEASE'