【发布时间】:2016-07-20 15:40:12
【问题描述】:
如何使用 Java 获取当前项目的依赖项? 我在 Java 类中尝试此代码,但结果为空:
class Example implements Plugin<Project> {
void apply(Project project) {
project.getConfigurations().getByName("runtime").getAllDependencies();
}
}
感谢您的回答 JBirdVegas 。我尝试在 Java 上编写您的示例:
List<String> deps = new ArrayList<>();
Configuration configuration = project.getConfigurations().getByName("compile");
for (File file : configuration) {
deps.add(file.toString());
}
但有错误:
Cannot change dependencies of configuration ':compile' after it has been resolved.
当运行 gradle build 时
【问题讨论】:
-
我把
apply plugin: Example放在dependencies {...}块之后,它起作用了
标签: java gradle gradle-plugin