Gradle-测试目录之间的依赖关系

时间:2019-05-14 05:15:30

标签: gradle kotlin

我的gradle项目中有test / groovy和test / kotlin

如何告诉我,在编译和测试中,test / groovy中的运行类取决于test / kotlin中的类?

示例项目: build.gradle

plugins {
    id 'groovy'
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.31'
}

group 'test'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.5.1'
    testCompile group: 'org.spockframework', name: 'spock-core', version:     "1.3-RC1-groovy-2.5"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

src / test / groovy中的Groovy类:

import spock.lang.Specification

class SomeSpec extends Specification {
    def test1(){
        when:
        def c = new SomeClass()
        then:
        1 == 1
    }
}

src / test / kotlin中的Kotlin类

class SomeClass {
}

我看到kotlin在Groovy之前编译了,但是仍然无法构建:

> Task :assemble UP-TO-DATE
> Task :compileTestKotlin UP-TO-DATE
> Task :compileTestJava NO-SOURCE

> Task :compileTestGroovy FAILED
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1     (file:/C:/Users/User/.gradle/caches/modules-2/files-    2.1/org.codehaus.groovy/groovy/2.5.4/86b94e2949bcff3a13b7ad200e4c5299b52ad994/groovy-2.5.4.jar) to constructor     java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of     org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal         reflective access operations
WARNING: All illegal access operations will be denied in a future release
 startup failed:
C:\work\test-gradle\src\test\groovy\SomeSpec.groovy: 6: unable to resolve     class SomeClass 
 @ line 6, column 17.
           def c = new SomeClass()
               ^

1 error

1 个答案:

答案 0 :(得分:1)

我通过添加

解决了
 compileTestGroovy.classpath += files(compileTestKotlin.destinationDir)