Gradle Groovy 项目错误:无法找到或加载主类

问题描述 投票:0回答:0

我终于能够获得一个与 Eclipse 一起工作的 Gradle 应用程序项目。 (出于某种奇怪的原因,当您使用 Eclipse 创建 Gradle 项目时,它会创建一个库(即不可执行),并且没有选择其他项目形式的选项。)

我不仅能够让它在 Eclipse 中工作(即当我“刷新 Gradle 项目”时没有错误),而且能够

gradle clean build
它。

但是,当我尝试

gradle run
它时,我面临问题:

$ gradle run --args="--jsonConfig cliConfig.json"

> Task :lib:run FAILED
Error: Could not find or load main class com.signaturemd.sposZohoMergeScript.App
Caused by: java.lang.ClassNotFoundException: com.signaturemd.sposZohoMergeScript.App

build.gradle
存在于 child
lib
文件夹中,定义为:

plugins {
    id 'application'
}

application { 
    mainClass = 'com.signaturemd.sposZohoMergeScript.App'
}

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

// SOURCE: ChatGPT AI
task createJar(type: Jar) {
    manifest {
        attributes 'Main-Class': 'com.signaturemd.sposZohoMergeScript.App'
    }
    baseName = 'SposZohoMergeScript' // deprecated
    from(sourceSets.main.output) {
        include '**/*'
    }
    with jar
}

dependencies {
    // Use JUnit Jupiter for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'

    // This dependency is exported to consumers, that is to say found on their compile classpath.
    // api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:30.1.1-jre'
    
    // https://mvnrepository.com/artifact/org.apache.poi/poi
    implementation 'org.apache.poi:poi:5.2.3'
    // https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
    implementation 'org.apache.poi:poi-ooxml:5.2.3'
    
    // https://mvnrepository.com/artifact/org.apache.groovy/groovy-cli-commons
    implementation 'org.apache.groovy:groovy-cli-commons:4.0.9'
    
    // https://mvnrepository.com/artifact/org.apache.groovy/groovy-json
    implementation 'org.apache.groovy:groovy-json:4.0.9'
    
    
}

tasks.named('test') {
    // Use JUnit Platform for unit tests.
    useJUnitPlatform()
}

我的项目结构,我没有从 Eclipse Gradle 项目结构中改变,是这样的:

此外,位于项目根文件夹中的

settings.gradle
没有以任何方式从Eclipse Gradle插件生成的内容中修改:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * The settings file is used to specify which projects to include in your build.
 *
 * Detailed information about configuring a multi-project build in Gradle can be found
 * in the user manual at https://docs.gradle.org/7.2/userguide/multi_project_builds.html
 */

rootProject.name = 'com.signaturemd.sposZohoMergeScript'
include('lib')

我的

build.gradle
文件或我的项目结构有什么问题?

eclipse gradle groovy command-line-interface
© www.soinside.com 2019 - 2024. All rights reserved.