无法为扩展 "应用程序 "设置未知属性 "mainClass"。

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

版本为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

但我在这一行出现错误。

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

这里的细节:

.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
java gradle
1个回答
1
投票

修改 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'
}

运行这个命令。gradle run

© www.soinside.com 2019 - 2024. All rights reserved.