문제

I've been getting my feet wet with Gradle for a school project (not an assignment) and I have this project that is divided into two folder, src/main/scala and src/test/scala.

As you can probably tell, the test folder stores my Unit Tests but for some reason I can't get Gradle to find them and tun them as it should. I'm using Scala with ScalaTest for this project.

Is there any way to tell Gradle where to look for test files? Or is there any logical explanation to why it isn't detecting my files?

This is my build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'scala'

repositories {
    mavenCentral()
}

sourceSets {
    main {
        scala {
            srcDirs = ['src/scala']
        }
    }
    test {
        scala {
            srcDirs = ['test/scala']
        }
    }
}

dependencies {
    compile 'org.scala-lang:scala-library:2.10.3'
    testCompile 'junit:junit:4.10'
    testCompile 'org.scalatest:scalatest_2.10:2.1.+'
}

test {
    useJUnit()
    testLogging {
        // Show that tests are run in the command-line output
        events 'started', 'passed'
    }
}   
도움이 되었습니까?

해결책

As described in the gradle scala plugin, you can change the location of the source and test directory by adding something like the following:

sourceSets {
    main {
        scala {
            srcDirs = ['src/scala']
        }
    }
    test {
        scala {
            srcDirs = ['test/scala']
        }
    }
}

다른 팁

I figured out the correct build.gradle to get it to work thanks to @ditkin 's reply. Turns out I needed to put the full src/main/scala and src/test/scala.

apply plugin: 'scala'
apply plugin: 'eclipse'

repositories {
    mavenCentral()
}

sourceSets {
    main {
        scala {
            srcDirs = ['src/main/scala']
        }
    }
    test {
        scala {
            srcDirs = ['src/test/scala']
        }
    }
}

dependencies {
    compile 'org.scala-lang:scala-library:2.10.3'
    testCompile 'junit:junit:4.10'
    testCompile 'org.scalatest:scalatest_2.10:2.1.+'
}

test {
    useJUnit()
    testLogging {
        // Show that tests are run in the command-line output
        events 'started', 'passed'
    }
}   

Look here for detailed explanation how test works and configure them http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top