【问题标题】:Is it possible to extend a gradle build script configured in a binary plugin?是否可以扩展在二进制插件中配置的 gradle 构建脚本?
【发布时间】:2014-09-29 15:07:10
【问题描述】:

我在下面创建了一个 Gradle 插件:

class CommandServiceProjectPlugin implements Plugin<Project> {
public void apply(Project project) {
    project.buildscript{
        repositories {
            maven: {
                url: 'http://localhost:8081/artifactory/zailab-virtual-repo'
                credentials: {
                    username = "admin"
                    password = "password"
                }
            }
        }
        /*Spring Boot Gradle plugin */
        dependencies { 
            classpath: 'org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE' 
        }
    }
    project.apply plugin: 'spring-boot'
    project.apply plugin: 'java'
    project.apply plugin: 'eclipse'
    project.repositories {
        maven: {
            url: 'http://localhost:8081/artifactory/zailab-virtual-repo'
        }
    }
    project.dependencies  {
        /*Spring Boot dependencies */
        compile: 'org.springframework.boot:spring-boot-starter-test'
        compile: 'org.springframework.boot:spring-boot-starter-aop'
        compile: 'org.springframework.boot:spring-boot-starter-data-mongodb'
        compile: 'org.springframework.boot:spring-boot-starter-integration'
        compile: 'org.springframework.boot:spring-boot-starter-amqp'
        /*Axon dependencies */
        compile: 'org.axonframework:axon-core:2.3.1'
        compile: 'org.axonframework:axon-mongo:2.3.1'
    }
}
}

然后我将插件应用到另一个项目中,如下所示,但似乎构建脚本定义覆盖/冲突,因为找不到“spring-boot”插件。我是在尝试不可能的事情,还是有其他方法可以实现我想要做的事情?

buildscript {
repositories {
    maven {
        url 'http://localhost:8081/artifactory/zailab-virtual-repo'
        credentials {
            username = "admin"
            password = "password"
        }
    }
}
dependencies {
    classpath(group: 'com.zailab', name: 'zailab-command-service-build', version: '1.0.0- SNAPSHOT')
 }
}
apply plugin: 'com.zailab.command.service.project'

谢谢, 罗斯科

【问题讨论】:

    标签: plugins build gradle build-script


    【解决方案1】:

    据我所知,不可能通过插件以编程方式添加构建脚本依赖项。 原因是构建脚本生命周期 - 插件的 apply 方法的调用发生在项目的类路径配置已经解决之后。

    您应该在项目的构建脚本中配置构建脚本,或者使用插件打包类路径依赖项。

    【讨论】:

    • 或者在插件模块的POM/Ivy描述符中列出依赖关系。
    • 有人可以举一个例子(或两者都有)。谢谢
    猜你喜欢
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2013-06-30
    相关资源
    最近更新 更多