문제

I have a single Gradle project that I am trying to organize in separate source folders. We want to adopt the convention that the project will have a bunch of "feature" folders, each with its own main/test folders as per the example:

feature1/main/java
feature1/test/java
feature2/main/java
feature2/test/java

So I started writing some Groovy to manage this automatically in my build script:

files { file('./').listFiles() }.collect { relativePath(it) }.each { f ->
  if (file(f).isDirectory()) {
    def m = f + '/main/java'
    def t = f + '/test/java'
    if (file(m).exists() && file(m).isDirectory()) {
      sourceSets.main.java.srcDir m
    }
    if (file(t).exists() && file(t).isDirectory()) {
      sourceSets.test.java.srcDir t
      task('test' + f, type: Test) {
        // ?!?
      }
    }
  }
}

The gist of the above code is to add the main/test folders to the source folders and to add a new test task that will execute only the tests for the specific feature. However, I can't seem to figure out a way to tell Gradle to only run tests contained in that specific folder.

I tried using include but it looks like that only works to filter packages and class names. I feel like this should be simple. What am I missing here?

도움이 되었습니까?

해결책 3

This was indeed quite simple. I modified the snippet above as follows:

task('test' + f, type: Test) {
  include fileTree(t).collect { 
    '**/' + it.name.replaceAll("\\.java", "\\.class") 
  }
}

which gives me the desired result without any additional configuration.

다른 팁

You'll need to set at least testClassesDir and classpath. For details, see Test in the Gradle Build Language Reference.

take a look at: gradle-1.11\samples\java\multiproject\ or get the gradle plugin for eclipse (see https://github.com/spring-projects/eclipse-integration-gradle/ or http://estiloasertivo.blogspot.com/2013/03/tutorial-howto-install-and-configure.html) and use it to generate a projecy with subprojects.

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