Gradle: custom source set as dependency for the main and test ones

一笑奈何 提交于 2019-12-10 00:58:46

问题


I've created custom source set in Gradle project to keep all generated code:

sourceSets {
  generated {
    java {
      srcDir 'src/generated/java'
    }
    resources {
      srcDir 'src/generated/resources'
    }
  }
}

I want to make the result of this source set's code compilation available at compile and run time for main and test source sets.

What's the right semantic way to do it in Gradle?

UPDATE:

As suggested here: How do I add a new sourceset to Gradle? doesn't work for me, I still get java.lang.ClassNotFoundException when I launch my app (though compilation and unit tests run fine). Here is what I tried:

sourceSets {
  main {
    compileClasspath += sourceSets.generated.output
    runtimeClasspath += sourceSets.generated.output
  }

  test {
    compileClasspath += sourceSets.generated.output
    runtimeClasspath += sourceSets.generated.output
  }
}

回答1:


sourceSets {
    main {
        compileClasspath += generated.output
        runtimeClasspath += generated.output
    }
}

Same for the test source set.



来源:https://stackoverflow.com/questions/21161845/gradle-custom-source-set-as-dependency-for-the-main-and-test-ones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!