我已遵循本指南:
http://www.gradle.org/docs/current/userguide/custom_plugins.html
创建具有以下结构/文件的独立 gradle 插件:
my-gradle-plugin
> src
> main
> java
> com
> mygroup
> MyGradlePlugin.groovy
> build.gradle
> settings.gradle
构建.gradle:
apply plugin: 'groovy'
dependencies {
compile gradleApi()
groovy localGroovy()
}
apply plugin: 'maven'
repositories {
mavenCentral()
}
group = 'com.mygroup'
version = '1.0.0-SNAPSHOT'
MyGradlePlugin.groovy:
package com.mygroup
import org.gradle.api.*
class MyGradlePlugin implements Plugin<Project> {
void apply(Project project) {
print " project.name " + project.name + "\n"
print " project.dependencies " + project.dependencies + "\n"
// How do we iterate each dependency and print artifactId, group, version??
// project.dependencies.each {
// compile(it) {
// print it.next()
// print it.name
// }
// }
project.configurations.each {
print it.dump()
}
}
}
在另一个项目中,我使用/应用这个插件:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
repositories {
mavenLocal()
}
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath group: 'com.mygroup', name: 'my-gradle-plugin', version: '1.0.0-SNAPSHOT'
}
}
dependencies {
compile group: 'commons-codec', name: 'commons-codec', version: '1.4'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.7.0'
}
install.doLast {
apply plugin: 'my-gradle-plugin'
}
但是如何从MyGradlePlugin.groovy中的 apply 方法迭代公共依赖项并打印它们的坐标(artifactId、groupId、version)?