2

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

文档指出:

在您的 build.gradle 中,您应该从 JAR 文件中排除已编译的类:

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

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

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

4

1 回答 1

2

请参阅https://github.com/jeffbrown/excludesdemo上的项目。这包括https://github.com/jeffbrown/excludesdemo/tree/master/grails-app/domain下的 2 个域类。

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

jar {
    exclude 'package1/**'
}

当您运行时,./gradlew jar您应该会看到生成的 jar 文件build/libs/excludesdemo-0.1-SNAPSHOT.jar包含package2/Author.class和不包含package1/Person.class.

于 2015-06-28T13:36:10.660 回答