Gradle-测试目录之间的依赖关系 [英] Gradle - Dependencies between test directories

查看:121
本文介绍了Gradle-测试目录之间的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have test/groovy and test/kotlin in my gradle project

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

How do I tell that in compilation and test running classes in test/groovy depend on classes in test/kotlin?

示例项目: build.gradle

Example project: 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类:

Groovy class in src/test/groovy:

import spock.lang.Specification

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

src/test/kotlin中的Kotlin类

Kotlin class in src/test/kotlin

class SomeClass {
}

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

I see that kotlin compiled before Groovy, but still build fails:

> 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

推荐答案

我通过添加

 compileTestGroovy.classpath += files(compileTestKotlin.destinationDir)

这篇关于Gradle-测试目录之间的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆