3

I've created a Gradle plugin below:

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

I then apply the plugin within another project as below, but it seems the buildscript definitions override/conflict as the 'spring-boot' plugin cannot be found. Am I attempting the impossible or is there perhaps another way to achieve what I am trying to do?

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'

Thanks, Roscoe

Roscoe Lotriet
  • 101
  • 1
  • 8

1 Answers1

1

As far as I know, it's not possible to add build script dependencies programmatically from a plugin. Reason for this is build script life cycle - invocation of plugins' apply method happens after the project's classpath configuration had already been resolved.

You should either configure the buildscript in project's build script, or package classpath dependencies with the plugin.

Sean
  • 169
  • 3