罗路遥
罗路遥

Reputation: 185

Get right dependencies name in custom plugin

  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
    }
  }
}

In this example, you can try to get dependencies name inside custom plugin class. But it's different between contents of output and the expected . I expect that,

'com.google.guava:guava:18.0'

But output is

org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependenciesHandler_Decorate@174b0a8

Upvotes: 0

Views: 80

Answers (1)

ayaye
ayaye

Reputation: 451

Almost duplicate of this question: How to iterate gradle dependencies in custom gradle plugin?

Short answer:

class LolPlugin implements Plugin<Project> {
  public void apply(Project p) {
    p.buildscript.configurations.each {
     it.allDependencies.each {
        println "${it.group}:${it.name}:${it.version}"
      }
    }
  }
}

Upvotes: 1

Related Questions