I am attempting to make Spring Boot 2.2.x application (Java 13) with Code-First approach using Hibernate and Liquibase. I would like to generate migrations base on difference between Entities object and database.
OS - Win 10 and Mint 18
Build system - gradle 6.0.
Database - Postgres SQL.
I installed liquibase utilities (3.8.2).
My gradle script:
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'net.ltgt.gradle:gradle-apt-plugin:0.18'
classpath 'org.postgresql:postgresql:42.2.9'
classpath 'org.liquibase:liquibase-core:3.8.2'
classpath "org.liquibase:liquibase-gradle-plugin:2.0.2"
}
}
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'org.liquibase.gradle' version '2.0.2'
id 'java'
}
group = 'com.goodt.drive'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '13'
targetCompatibility = '13'
diff.dependsOn compileJava
diffChangeLog.dependsOn compileJava
generateChangelog.dependsOn compileJava
dependencies {
liquibaseRuntime 'org.liquibase:liquibase-core:3.8.2'
liquibaseRuntime "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
liquibaseRuntime 'org.springframework.boot:spring-boot:2.2.1.RELEASE'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
liquibaseRuntime 'org.postgresql:postgresql:42.2.9'
liquibaseRuntime 'org.hibernate:hibernate-core:5.4.10.Final'
liquibaseRuntime 'ch.qos.logback:logback-core:1.2.3'
liquibaseRuntime 'ch.qos.logback:logback-classic:1.2.3'
liquibaseRuntime sourceSets.main.output
}
def dbChangeLog = "$projectDir/src/main/resources/db/changelog/changelog.xml"
def generatedChangeLog = "$projectDir/src/main/resources/db/changelog/generated_changelog.xml"
liquibase {
activities {
main {
changeLogFile dbChangeLog
outputFile generatedChangeLog
driver "org.postgresql.Driver"
classpath "$projectDir/lib/postgresql-42.2.9.jar"
url "jdbc:postgresql://localhost:5432/webportal"
username "developer"
password "123"
referenceUrl "hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect"
//referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
}
}
}
When i am runnung liquibase diff command from gradle script like this: .\gradlew.bat diff i am getting following output:
> Task :diff
liquibase-plugin: Running the 'main' activity...
12:48:14.372 INFO [liquibase.integration.commandline.Main]: Starting Liquibase at ёЁ, 15 эт. 2020 12:48:14 YEKT (version 3.8.2 #26 built at Tue Nov 26 04:53:39 UTC 2019)
12:48:15.323 INFO [liquibase.integration.commandline.Main]: No Liquibase Pro license key supplied. Please set liquibaseProLicenseKey on command line or in liquibase.properties to use Liquibase Pro features.
12:48:15.325 INFO [liquibase.integration.commandline.Main]: Liquibase Community 3.8.2 by Datical
12:48:15.614 ERROR [liquibase.integration.commandline.Main]: Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:132)
at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1604)
at liquibase.integration.commandline.Main.doMigration(Main.java:1200)
at liquibase.integration.commandline.Main.run(Main.java:229)
at liquibase.integration.commandline.Main.main(Main.java:143)
Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:263)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:97)
... 4 common frames omitted
Caused by: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:200)
... 6 common frames omitted
The stack trace indicates that Liquibase Cannot find database driver and Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
This indicates that you should add the liquibase-hibernate jar to your dependencies and uncomment the referenceDriver line in your gradle script.
I updated liquibase (in gradle) to version 3.8.4
I added liquibaseRuntime lines with liquibase-hibernate and spring-data-jpa
I added to liquibase-hibernate and spring-data-jpa classpath {} section of gradle script.
One more addition, i write an article about how to use liquibase you could find it here: https://m-ushakov.medium.com/code-first-with-spring-boot-hibernate-and-liquibase-48f5c9998d95
Whole Gradle script:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'net.ltgt.gradle:gradle-apt-plugin:0.18'
classpath 'org.postgresql:postgresql:42.2.9'
classpath 'org.liquibase.ext:liquibase-hibernate5:3.8'
classpath 'org.liquibase:liquibase-core:3.8.4'
classpath 'org.liquibase:liquibase-gradle-plugin:2.0.2'
classpath 'org.springframework.data:spring-data-jpa:2.2.1.RELEASE'
}
}
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'org.liquibase.gradle' version '2.0.2'
id 'java'
}
group = 'com.wissance.webportal'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '13'
targetCompatibility = '13'
ext {
set('springCloudVersion', "Hoxton.RC2")
set('queryDslVersion', "4.1.3")
set('swaggerVersion', "2.9.2")
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
diff.dependsOn compileJava
diffChangeLog.dependsOn compileJava
generateChangelog.dependsOn compileJava
dependencies {
// spring boot
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-hateoas'
compile 'org.springframework.boot:spring-boot-starter-web'
// spring cloud
//implementation 'org.springframework.cloud:spring-cloud-starter-config'
//implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// JAX-B dependencies for JDK 9+
implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
// other
compile 'org.postgresql:postgresql:42.2.1'
compile 'com.h2database:h2'
compile 'org.hibernate:hibernate-core:5.4.10.Final'
compileOnly 'org.projectlombok:lombok'
//runtimeOnly 'org.postgresql:postgresql'
runtime 'javax.xml.bind:jaxb-api'
//runtime 'org.liquibase:liquibase-core'
liquibaseRuntime 'org.liquibase:liquibase-core:3.8.4'
liquibaseRuntime "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
liquibaseRuntime 'org.springframework.boot:spring-boot:2.2.1.RELEASE'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
liquibaseRuntime 'org.postgresql:postgresql:42.2.9'
liquibaseRuntime 'org.springframework.data:spring-data-jpa:2.2.1.RELEASE'
liquibaseRuntime 'org.hibernate:hibernate-core:5.4.10.Final'
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.8'
liquibaseRuntime 'ch.qos.logback:logback-core:1.2.3'
liquibaseRuntime 'ch.qos.logback:logback-classic:1.2.3'
liquibaseRuntime sourceSets.main.output
// TESTS
//testImplementation('org.springframework.boot:spring-boot-starter-test') {
// exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
//}
testCompile('org.junit.jupiter:junit-jupiter-engine:5.2.0')
// QueryDsl
compile "com.querydsl:querydsl-core:${queryDslVersion}"
compile "com.querydsl:querydsl-jpa:${queryDslVersion}"
// Swagger
compile "io.springfox:springfox-swagger2:${swaggerVersion}"
compile "io.springfox:springfox-swagger-ui:${swaggerVersion}"
annotationProcessor (
"org.projectlombok:lombok",
"com.querydsl:querydsl-apt:${queryDslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
"javax.annotation:javax.annotation-api:1.3.2"
)
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
def dbChangeLog = "$projectDir/src/main/resources/db/changelog/changelog.xml"
def generatedChangeLog = "$projectDir/src/main/resources/db/changelog/generated_changelog.xml"
/*task copyToLib(type: Copy) {
into "$buildDir/output/libs"
from configurations.runtime
}*/
liquibase {
activities {
main {
changeLogFile dbChangeLog
outputFile generatedChangeLog
driver "org.postgresql.Driver"
// classpath "$projectDir/lib/postgresql-42.2.9.jar"
url "jdbc:postgresql://localhost:5432/webportal
password "123"
referenceUrl "hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect"
referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
}
}
}
jar {
enabled = true
manifest {
attributes 'Main-Class': 'com.wissance.webportal.Application'
}
}
test {
useJUnitPlatform()
}
Not sure if it's related to the errors you are experiencing or not, but Liquibase recently posted a 3.8.4 version that corrects some Spring Boot errors with Java 9+. https://www.liquibase.org/2019/12/liquibase-3-8-4-released.html
I'd try running that to see if it resolves the issue for you.
Related
I Have the following build.gradle file:
buildscript {
ext {
scalaVersion = '2.12.10'
gatlingVersion = '3.8.4'
}
all {
resolutionStrategy {
force("com.google.protobuf:protobuf-java:2.4.1")
}
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'log4j', module: 'log4j'
}
}
dependencies {
implementation("org.scala-lang:scala-library:${scalaVersion}")
implementation("org.scala-lang:scala-reflect:${scalaVersion}")
implementation("io.gatling:gatling-app:${gatlingVersion}")
implementation("io.gatling.highcharts:gatling-charts-highcharts:${gatlingVersion}")
implementation('org.scala-lang.modules:scala-parser-combinators_2.12:1.1.2')
implementation('io.netty:netty-all:4.1.81.Final')
}
When I try to build it shows me:
* What went wrong:
Execution failed for task ':compileTestScala'.
> Could not resolve all dependencies for configuration ':zinc'.
> Conflict(s) found for the following module(s):
- org.scala-lang:scala-library between versions 2.12.10, 2.12.2, 2.12.8, 2.12.4 and 2.12.0
- org.scala-lang:scala-reflect between versions 2.12.10 and 2.12.8
Why it shows me to choose from these version when I already import one of these versions?
Thanks in advance
With Flyway version 7.5.0, it still works fine. Version 7.5.1 and 7.5.2 however, produce the following error:
[...]
java.lang.IllegalStateException: Unexpected error occurred while initializing the data source
at com.google.common.base.Preconditions.checkState(Preconditions.java:459)
at io.zonky.test.db.flyway.DefaultFlywayDataSourceContext.getTarget(DefaultFlywayDataSourceContext.java:89)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:195)
at com.sun.proxy.$Proxy65.getConnection(Unknown Source)
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:59)
at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:69)
at org.flywaydb.core.Flyway.execute(Flyway.java:507)
at org.flywaydb.core.Flyway.migrate(Flyway.java:165)
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
[...]
Any idea, what's the problem or how to fix it?
Below is the code of my minimal example to reproduce the problem:
Dockerfile
FROM openjdk:11.0.10-jdk AS base
# Needed for embedded PostgreSQL-server to start during integration tests.
# see: https://github.com/zonkyio/embedded-database-spring-test
RUN groupadd --system --gid 1000 test
RUN useradd --system --gid test --uid 1000 --shell /bin/bash --create-home test
USER test
WORKDIR /home/test
ADD . /home/test/
RUN ./gradlew test
build.gradle
buildscript {
ext {
kotlinVersion = '1.4.21'
springBootVersion = '2.4.2'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'kotlin-jpa'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.acme'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: "${springBootVersion}"
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.18'
implementation group: 'org.flywaydb', name: 'flyway-core', version: '7.5.2'
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: "${kotlinVersion}"
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}"
testImplementation group: 'junit', name: 'junit', version: '4.13.1'
testImplementation group: 'io.zonky.test', name: 'embedded-database-spring-test', version: '1.6.2'
}
test {
testLogging {
exceptionFormat = 'full'
}
}
compileKotlin.dependsOn(processResources)
compileJava.dependsOn(processResources)
settings.gradle
rootProject.name = 'flywayzonkytest'
src/main/kotlin/com/acme/flywayzonkytest/Application.kt
package com.acme.flywayzonkytest
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
#SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
src/main/resources/application.yml
spring:
flyway:
enabled: true
src/main/resources/db/migration/V1__thing.sql
CREATE TABLE thing (
some_id BIGINT PRIMARY KEY NOT NULL,
some_name VARCHAR NOT NULL
);
src/test/kotlin/com/acme/flywayzonkytest/integration/CreateContextTest.kt
package com.acme.flywayzonkytest.integration
import io.zonky.test.db.AutoConfigureEmbeddedDatabase
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
#RunWith(SpringRunner::class)
#AutoConfigureEmbeddedDatabase
#SpringBootTest
class CreateContextTest {
#Test
fun `test create context`() {
}
}
Flyway had some breaking changes between version 7.5.0 and 7.5.1. The maintainer of zonkyio/embedded-database-spring-test just implemented a fix/workaround in his library, which is included in version 1.6.3. :-)
I have just started working on the scala and gradle. I want to know how we can call any scala method from the gradle build file. Can somebody please help me?
From comment: I want to run multiple files present in a directory. So in order to get all the files in the directory, I have written a method in scala. That method I am trying to call from build.gradle file
Gradle allows to specify dependencies of build script itself inside buildscript{ dependencies { ... } } (not to be confused with project dependencies inside ordinary dependencies { ... }).
For example here I added Shapeless dependency and used an HList in build.gradle
build.gradle
buildscript{
dependencies {
classpath group: 'com.chuusai', name: 'shapeless_2.13', version: '2.4.0-M1'
}
}
plugins {
id 'java'
id 'scala'
id 'application'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
// compile group: ...
}
application {
mainClassName = 'App'
}
import shapeless.*
task hello {
doLast {
HList l = new $colon$colon(1, new $colon$colon("a", new HNil$()))
println l
}
}
Terminal
$ ./gradlew hello
Output
> Task :hello
1 :: a :: HNil
BUILD SUCCESSFUL in 457ms
1 actionable task: 1 executed
So you can compile your Scala sources, package classes into jar, publish it locally and specify your local dependency in
buildscript{
dependencies {
classpath group: 'yourOrganization', name: 'yourArtifact', version: 'yourVersion'
}
}
and then call methods from your Scala code in build.gradle.
I have project that uses gradle, scala, scalatest and the gradle-scalatest-plugin.
I have several tests and they are compiled. But when the run part of them is executed, the gradle is stuck on "Dicovery starting." infinitely.
So I used gradle --debug test to see what is happening. But besides the status information about memory of jvm and lock acquiring, there is no information why it is stuck.
build.gradle File:
buildscript {
ext.scala_version = "2.12"
ext.akka_version = "2.5"
ext.monocle_version = "1.5.0"
ext.circe_version = "0.8+"
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.diffplug.gradle:goomph:3.9.0"
}
}
plugins {
id "java"
id "scala"
id "com.github.maiflai.scalatest" version "0.19"
id "com.athaydes.osgi-run" version "1.5.4"
id "org.dm.bundle" version "0.10.0"
// For interoperability with Other Company Eclipse P2 Repository
id "com.diffplug.gradle.p2.asmaven" version "3.9.0"
}
group "project.scalatest"
version 0.1
repositories {
mavenCentral()
jcenter()
}
sourceSets {
test {
java {
srcDirs = ['test/main/java']
}
scala {
srcDirs = ['test/main/scala']
}
}
}
runOsgi {
bundles += project
}
bundle {
instruction '-dsannotations', '*'
}
test {
}
// Adding the Other Company Eclipse P2 project Core Repo as dependency
p2AsMaven {
group 'project', {
repo 'https://other-company.de/p2/'
iu 'de.other-company.project.core'
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar', '*.java'])
compile "org.osgi:org.osgi.core:6.0+"
compile "org.osgi:org.osgi.service.log:1.3+"
compile "org.osgi:org.osgi.service.component:1.3+"
compile "org.osgi:org.osgi.service.component.annotations:1.3+"
compile "project:de.other-company.project.core:+"
// Include the program repository code as dependency
//compile fileTree(dir: "../repository")
compile "org.scala-lang:scala-library:$scala_version+"
compile "com.typesafe.akka:akka-osgi_$scala_version:$akka_version+"
compile "io.circe:circe-core_$scala_version:$circe_version"
compile "io.circe:circe-generic_$scala_version:$circe_version"
compile "io.circe:circe-parser_$scala_version:$circe_version"
compile "io.circe:circe-optics_$scala_version:$circe_version"
compile "com.github.julien-truffaut:monocle-core_$scala_version:$monocle_version"
compile "com.github.julien-truffaut:monocle-macro_$scala_version:$monocle_version"
compile "org.slf4j:slf4j-api:1.7.+"
compile "org.slf4j:slf4j-simple:1.7.+"
compile "org.slf4j:osgi-over-slf4j:1.7.+"
testCompile "com.typesafe.akka:akka-testkit_$scala_version:$akka_version+"
testCompile "org.scalatest:scalatest_$scala_version:3.2+"
testCompile "org.scalactic:scalactic_$scala_version:3.2+"
testCompile "org.scalacheck:scalacheck_$scala_version:1.13+"
testCompile "org.mockito:mockito-core:2.+"
testRuntime "org.pegdown:pegdown:1.4+"
osgiRuntime "org.apache.felix:org.apache.felix.configadmin:1.8+"
osgiRuntime "org.apache.felix:org.apache.felix.scr:2.0+"
osgiRuntime "org.apache.felix:org.apache.felix.log:1.0+"
}
So I found the solution myself :)
I did some crappy solution to find and use files in the test.
After a research how to do it properly getClass.getResource("...") the problem went away.
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
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.