如何从 Grails 3 插件中排除 类

How can I exclude classes from a Grails 3 plugin

我正在尝试将 Grails 2 插件转换为 Grails 3,但我无法从生成的 jar 中排除几个仅在测试中使用的域 类。

documentation 状态:

in your build.gradle you should exclude the compiled classes from the JAR file:

jar {
    exclude "com/demo/**/**"
}

...但是如果我尝试这样做,我会从 Gradle 得到以下错误: Could not find method jar() for arguments [build_64zizslf5a7zfo329yz5tdsoi$_run_closure1@566c53c] on root project '...'

我可以 post 整个堆栈跟踪,但它看起来不是很有用。我正在使用 Gradle 2.3,由 create-plugin 命令生成的默认 Gradle 包装器提供。我也没有对 build.gradle 进行任何其他更改,因为我的插件不需要任何外部依赖项。

https://github.com/jeffbrown/excludesdemo. That includes 2 domain classes under https://github.com/jeffbrown/excludesdemo/tree/master/grails-app/domain 查看项目。

位于 https://github.com/jeffbrown/excludesdemo/blob/72896a3f88f617d530bbdde8976d5bfe8d1e820a/build.gradle#L73 的顶级 build.gradle 文件包含以下内容:

jar {
    exclude 'package1/**'
}

当你 运行 ./gradlew jar 你应该看到在 build/libs/excludesdemo-0.1-SNAPSHOT.jar 处生成的 jar 文件确实包含 package2/Author.class 但不包含 package1/Person.class.