简体   繁体   English

Gradle:自定义源设置为主要和测试的依赖

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

I've created custom source set in Gradle project to keep all generated code: 我在Gradle项目中创建了自定义源集,以保留所有生成的代码:

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. 我想在maintest源集的编译和运行时使得源集的代码编译结果可用。

What's the right semantic way to do it in Gradle? 在Gradle中以正确的语义方式做什么?

UPDATE: 更新:

As suggested here: How do I add a new sourceset to Gradle? 如此处所示: 如何向Gradle添加新的源集? doesn't work for me, I still get java.lang.ClassNotFoundException when I launch my app (though compilation and unit tests run fine). 对我来说不起作用,当我启动我的应用程序时,我仍然得到java.lang.ClassNotFoundException (虽然编译和单元测试运行正常)。 Here is what I tried: 这是我尝试过的:

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

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

Same for the test source set. 对于test源集也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM