2

我必须为我的自定义插件声明依赖项buildscript

buildscript {
    dependencies {
        classpath files (["project/path/to/compiled/classes"])

        classpath ("com.project.plugin:custom-plugin:${pluginVersion}")
    }
}

是否有可能以某种方式在插件类中获取它们

public class PluginClass implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        project.getExtensions().create("pluginConfig", PluginExtension.class);
        project.getTasks().create("plugin", PluginTask.class);
    }

}

或使用扩展名传递它们?就像是:

porject.getDependencies().create(classpath_dependency)
4

1 回答 1

5

dependencies您可以configurations通过project实例访问两者:

buildscript {
  repositories {
    mavenCentral()
  }

  dependencies {
    classpath 'com.google.guava:guava:18.0'
  }
}

apply plugin: LolPlugin

class LolPlugin implements Plugin<Project> {
  public void apply(Project p) {
    p.buildscript.dependencies.each {
      println it
    }
    p.buildscript.configurations.classpath.each {
      println it
    }
  }
}
于 2015-12-01T11:50:45.733 回答