我正在编写一个自定义gradle插件Foo,我想加载org.springframework.boot插件
进入应用Foo插件的项目。我可以用这种方式加载其他各种插件,但这
特定的插件不希望行为相同。

Foo build.gradle

buildscript {
    ext {
        springBootVersion = "2.1.3.RELEASE"
    }
}

apply plugin: "groovy"

repositories {
    maven { url "http://custom.repo/blah" }
}

dependencies {
    implementation gradleApi()
    implementation localGroovy()

    implementation("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}

Foo插件
class BuildPlugin implements Plugin<Project> {

    @Override
    void apply(Project project) {
        project.repositories {
            maven { url "http://custom.repo/blah" }
        }

        project.plugins.apply("org.springframework.boot")
    }
}

项目build.gradle
buildscript {
    dependencies {
        classpath files("/some/cool/path/foo-plugin.jar")
    }
}

apply plugin: "com.whatever.foo-id"

项目构建输出
$ ./gradlew --stacktrace clean build

FAILURE: Build failed with an exception.

* Where:
Build file '/cool/project/location/bar/build.gradle' line: 40

* What went wrong:
A problem occurred evaluating root project 'bar'.
> Failed to apply plugin [id 'com.whatever.foo-id']
   > Plugin with id 'org.springframework.boot' not found.

是否可以从插件2应用插件1,其中插件1是类路径依赖项?

最佳答案

这是不可能的。类路径是插入插件的原因,因此它们在插入之前就无法修改。

08-27 23:48
查看更多