IDEA在build.gradle.kts中报告ShadowJar任务的错误,而./gradlew run起作用

IDEA在build.gradle.kts中报告ShadowJar任务的错误,而./gradlew run起作用,gradle,intellij-idea,kotlin,Gradle,Intellij Idea,Kotlin,我正在使用Kotlin DSL进行gradle配置 ./gradlew工作正常,但IDEA仍然在build.gradle.kts中报告ShadowJar的错误 Type argument is not within its bounds. Expected:Task! Found: ShadowJar 问题: 对于ShadowJar任务,是否有任何对gradle和IDEA都适用的替代语法 复制发行的git回购: build.gradle.kts: import com.github.j

我正在使用Kotlin DSL进行gradle配置

./gradlew工作正常,但IDEA仍然在build.gradle.kts中报告ShadowJar的错误

Type argument is not within its bounds.
Expected:Task!
Found:   ShadowJar
问题: 对于ShadowJar任务,是否有任何对gradle和IDEA都适用的替代语法

复制发行的git回购:

build.gradle.kts:

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {

    kotlin("jvm") version "1.3.20"
    id("com.github.johnrengelman.shadow") version "4.0.4"

    application
}


group = "com.example"
version = "0.0.1"

repositories {
    jcenter()
    mavenCentral()
}

val junitVersion = "5.4.0"

dependencies {
    implementation(kotlin("stdlib", "1.3.20"))
    implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.20")

    compileClasspath("com.github.jengelman.gradle.plugins:shadow:4.0.4")

    implementation("org.slf4j:slf4j-api:1.7.21")
    implementation("ch.qos.logback:logback-core:1.2.3")
    implementation("ch.qos.logback:logback-classic:1.2.3")

    testImplementation("io.kotlintest:kotlintest-runner-junit5:3.3.1")
    testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
    testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
    runtime("org.junit.jupiter:junit-jupiter-engine:$junitVersion")

}

application {
    mainClassName = "com.example.App"
}


val test by tasks.getting(Test::class) {
    useJUnitPlatform()
    testLogging.showStandardStreams = true
    testLogging.events = setOf(TestLogEvent.PASSED, TestLogEvent.FAILED, TestLogEvent.SKIPPED, TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR)
}

tasks.withType<ShadowJar> {
    manifest {
        attributes["Implementation-Title"] = "Shadow Jar"
        attributes["Implementation-Version"] = version
        attributes["Main-Class"] = "com.example.App"
    }
    classifier = "jar-with-dependencies"
}
想法:

IDEA配置为使用gradle“包装器”任务配置

操作系统


compileClasspath
很可能会混淆gradle集成的概念

$ ./gradlew --version

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_201 (Oracle Corporation 25.201-b09)
OS:           Linux 4.15.0-46-generic amd64
IntelliJ IDEA 2019.1 (Community Edition)
Build #IC-191.6183.87, built on March 27, 2019
JRE: 1.8.0_202-release-1483-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-46-generic
$ uname -a
Linux qa-pc 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"