简体   繁体   English

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

[英]Could not set unknown property 'mainClass' for extension 'application

I'm using Gradle version 6.1 in my project.我在我的项目中使用 Gradle 6.1 版。

The build.gradle for the project is given below:该项目的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'
}

But when I run this command ./gradlew assemble , it is giving me error given below:但是当我运行这个命令./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

Modify build.gradle to this:将 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'
}

Run this commmand: ./gradlew build运行这个命令: ./gradlew build

You could try this (based off the source code ):你可以试试这个(基于源代码):

application {
    setMainClassName("some.package.Main")
}

There was a deprecation introduced in 6.4. 6.4 中引入了弃用。 It went from:它来自:

 application {
   mainClassName = "com.foo.bar.FooBar"
 }

To:至:

 application {
   mainClass.set("com.foo.bar.FooBar")
 }

The Docs:文档:

https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/JavaApplication.html#getMainClassName-- https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/JavaApplication.html#getMainClassName--

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法为 org.springframework.boot.gradle.dsl.SpringBootExtension 类型的对象设置未知属性“mainClass” - Could not set unknown property 'mainClass' for object of type org.springframework.boot.gradle.dsl.SpringBootExtension 无法为 org.springframework.boot.gradle.dsl.SpringBootExtension 类型的扩展“springBoot”设置未知属性“mainClassName” - Could not set unknown property 'mainClassName' for extension 'springBoot' of type org.springframework.boot.gradle.dsl.SpringBootExtension Gradle:无法在 Intellij 中设置未知属性“classDumpFile” - Gradle: could not set unknown property 'classDumpFile' in Intellij 无法在 Gradle 中设置未知属性“applicationDefaultJvmArgs” - Could not set unknown property 'applicationDefaultJvmArgs' in Gradle 无法为根项目设置未知属性“mainClassName” - Could not set unknown property 'mainClassName' for root project 出现错误“无法设置未知属性包括编译类路径” - Getting error "could not set unknown property include compile classpath" Windows -cp Mainclass无法加载 - Windows -cp Mainclass could not be loaded 在Eclipse中使用Maven使用mainClass创建Java应用程序-'找不到主类' - Creating a java application with a mainClass using Maven in Eclipse - 'Could not find the main class' 在spring-boot-maven-plugin中设置mainClass导致我需要显式设置'defaultServletName'属性 - Setting mainClass in spring-boot-maven-plugin causes me to need to set the 'defaultServletName' property explicitly 如何解决找不到或加载主类错误? - How to solve could not find or load mainclass error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM