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

帕维尔·伯恩斯坦(Pavel Bernshtam)

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

我如何在编译和测试中告诉测试/常规中的运行类取决于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
帕维尔·伯恩斯坦(Pavel Bernshtam)

我通过添加解决了

 compileTestGroovy.classpath += files(compileTestKotlin.destinationDir)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章