gpt4 book ai didi

java - 无法为扩展名“application”设置未知属性 'mainClass'

转载 作者:行者123 更新时间:2023-12-01 14:27:13 24 4
gpt4 key购买 nike

我在项目中使用的是Gradle 6.1版。
下面给出了该项目的 build.gradle :

plugins {
id 'application'
}

application {
mainClass = 'com.mytestproject.Main'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

group 'com.mytestproject'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
但是,当我运行此命令 ./gradlew assemble时,它给了我下面的错误:
./gradlew assemble

FAILURE: Build failed with an exception.

* Where:
Build file '/com/myproject/build.gradle' line: 6

* What went wrong:
A problem occurred evaluating root project 'JavaTestProject'.
> Could not set unknown property 'mainClass' for extension 'application' of type org.gradle.api.plugins.internal.DefaultJavaApplication.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 484ms

最佳答案

修改 build.gradle 到此:

apply plugin: "application"

mainClassName = "com.mytestproject.Main"

sourceCompatibility = 1.8
targetCompatibility = 1.8

group 'com.mytestproject'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
运行以下命令: ./gradlew build

关于java - 无法为扩展名“application”设置未知属性 'mainClass',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61976771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com