如何设置Gradle自定义ant任务类路径?

Dav*_* L. 5 java ant build gradle

我在我的代码库中有一个自定义Ant任务,我需要在Gradle中使用它.有很多关于如何使用打包在jar文件中的任务的示例,但这是不同的.

taskdef应该看起来像:

ant.taskdef(
    name: 'generator',
    classname: 'MyGenerator', 
    classpath: ???
)
Run Code Online (Sandbox Code Playgroud)

classpath应包括一切bin/(在我的代码被编译到),并在列出的所有罐子dependencies构建脚本的部分.如何填空?

我尝试了一些不同的东西,导致了类似The <taskdef> type doesn't support nested text data或典型的模糊信息NoClassDefFoundError.

Per*_*ler 2

我认为用户指南中的“在构建中使用自定义 Ant 任务”下描述了您想要执行的操作

基本上你想声明一个configuration,在该dependencies部分中添加依赖项,然后asPath在你的taskdef classpath

  • 如果这确实是您想要的,请使用“classpath: sourceSets.main.runtimeClasspath.asPath”。确保在任务操作中执行此操作,而不是在配置时执行此操作。 (7认同)