我正在尝试将 Grails 2 插件转换为 Grails 3,但我无法从生成的 jar 中排除几个仅在测试中使用的域类。
in your build.gradle you should exclude the compiled classes from the JAR file:
jar {
exclude "com/demo/**/**"
}
...但是如果我尝试这样做,我会从 Gradle 收到以下错误:
在根项目“...”上找不到参数 [build_64zizslf5a7zfo329yz5tdsoi$_run_closure1@566c53c] 的方法 jar()
我可以发布整个堆栈跟踪,但它看起来不是很有帮助。我使用的是 Gradle 2.3,由 create-plugin
命令生成的默认 Gradle 包装器提供。我还没有对 build.gradle
进行任何其他更改,因为我的插件不需要任何外部依赖项。
最佳答案
查看该项目 https://github.com/jeffbrown/excludesdemo 。其中包括 https://github.com/jeffbrown/excludesdemo/tree/master/grails-app/domain 下的 2 个域类.
顶级 build.gradle
文件位于 https://github.com/jeffbrown/excludesdemo/blob/72896a3f88f617d530bbdde8976d5bfe8d1e820a/build.gradle#L73包含以下内容:
jar {
exclude 'package1/**'
}
当您运行 ./gradlew jar
时,您应该会看到 build/libs/excludesdemo-0.1-SNAPSHOT.jar
生成的 jar 文件确实包含 package2/Author.class
并且不包含 package1/Person.class
。
关于grails - 如何从 Grails 3 插件中排除类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31074013/