【问题标题】:mainClassName not found which is not needed未找到不需要的 mainClassName
【发布时间】:2020-07-01 05:12:11
【问题描述】:

我正在创建一个根本没有主类的库。该库使用具有正在寻找 mainClassName 的应用程序插件的 Spring。我用 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'.


【问题讨论】:

  • 如果是 al 库,请不要应用 spring boot 插件。这仅用于创建可执行的 fatjar 并将重组您的 jar 格式。所以删除它。另一方面,您的依赖项中有冲突的版本(2.2.1 和 2.1.6),这最终会导致奇怪的错误。
  • 嗯,你能告诉我更多关于它将如何重组 jar 格式的信息吗?如果库需要 Spring Boot 插件,我该怎么办? @M.Deinum
  • 库永远不需要 spring boot 插件。 spring boot jar 会将类移动到非标准位置,将运行程序所需的 jar 添加到 lib 文件夹等。所以只需删除 spring boot 插件(您甚至可以通过设置 boot jar 在自己的答案中禁用它。启用为假)。

标签: spring spring-boot gradle plugins gradle-plugin


【解决方案1】:

添加

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

解决了我的问题。谢谢

【讨论】:

    【解决方案2】:

    想在 2022 年添加我的答案,因为接受的答案对我不起作用。然而,删除 springboot 插件就成功了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 1970-01-01
      • 2018-03-31
      • 1970-01-01
      相关资源
      最近更新 更多