java - Gradle 插件:无法将 Java.io.File 类的“A.txt”转换为 org.gradle.api.file.Property 类
问题描述
我正在尝试使用 DSL 编写插件:
model {
model1 {input = file(A.txt) output = file("/")}
model2 {input = file(A.txt) output = file("/")}
}
并基于model1和model2我将进行处理并将结果输出到输出目录中。
class Extension
{
final String name
final Property<file> input
final Property<file> output
@Inject
Extension(String name,ObjectFactory objectfactory)
{
this.name = name
input = objectfactory.property(File)
output = objectfactory.property(File)
}
}
///插件类
class Plugin implements Plugin<Project> {
@Override
void apply(final Project project) {
NamedDomainObjectContainer<Extension> container= project.container(Extension) {
name -> new Extension(name, project.getObjects());
}
project.getExtensions().add("model", container);
container.each {
String taskName = "model" + name;
project.tasks.create(taskName, Task) {
input.set(input)
output.set(output)
}
}
}
} </p>
//任务类
class Deploy extends DefaultTask
{
@InputFile
Property<File> input = project.objects.property(File)
@OutputFile
Property<File> output= project.objects.property(File)
@TaskAction
def task()
{
//custom logic
}
}
这段代码的灵感来自 https://guides.gradle.org/implementing-gradle-plugins/(ServerEnvironment Plugin)
但是当我运行它时,我无法将 Java.io.File 类的“A.txt”转换为 org.gradle.api.file.Property 类。
谁能告诉这里有什么问题和解决方法。
谢谢
额外观察:当我更改 = with .set in my build.gradle 错误更改为 stackoverflow
解决方案
推荐阅读
- azure - Azure 自定义视觉返回 {"code":"NotFoundIteration","message":"Invalid iteration"}
- rx-java2 - @RawQuery 和生成的 RxRoom.createFlowable(db, tables)
- azure - 如何将 docker 卷传输到 azure 中的 kubernetes 卷?
- java - 为什么我们不覆盖 Spring CRUD Repository 中的方法
- python-3.x - tensorflow教程中的基本分类
- json - 将 XML 转换为 JSON 的奇怪结果
- r - 从 violinboxplot 的子集标题中删除 facet.by 标签
- android - 对按钮进行编程以获得下一个焦点
- angular - 如何在 ionic 3 中使用 Observables
- javascript - 在获取用户时使用 Passport-jwt 时 req.user 未定义