gpt4 book ai didi

gradle - 如何在自定义gradle插件中获取project.sourceSets.test.runtimeClasspath

转载 作者:行者123 更新时间:2023-12-03 03:12:25 31 4
gpt4 key购买 nike

我想创建gradle插件,它将添加类型为 JavaExec 的其他任务

我有插件:

class CustomPlugin implements Plugin<Project> {
@Override
void apply(Project project) {

project.task('generate', type: JavaExec) {
main = 'some.package.ClassWithMainInTestScope'
args = ['some', 'arguments']
classpath project.sourceSets.test.runtimeClasspath
}
}
}

而且我有以下错误
FAILURE: Build failed with an exception.

* Where:
Build file '/home/pompei/IdeaProjects/greetgo.depinject/greetgo.depinject.gradle/build/test_projects/pr-20180720-164840-381-109260619/test/build.gradle' line: 3

* What went wrong:
An exception occurred applying plugin request [id: 'kz.greetgo.depinject.plugin']
> Failed to apply plugin [id 'kz.greetgo.depinject.plugin']
> Could not get unknown property 'sourceSets' for root project 'test' of type org.gradle.api.Project.

问题是:如何在插件中获取 project.sourceSets

最佳答案

尝试一下:

    final JavaPluginConvention javaPlugin = getProject().getConvention().getPlugin(JavaPluginConvention.class);
final SourceSetContainer sourceSets = javaPlugin.getSourceSets();
final SourceSet smoketest = sourceSets.findByName("smoketest");
this.testClasspath = smoketest.getRuntimeClasspath();

关于gradle - 如何在自定义gradle插件中获取project.sourceSets.test.runtimeClasspath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51441115/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com