Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Chore - Convert Maven build to Gradle #35

Open
hhandoko opened this issue Dec 21, 2016 · 6 comments
Open

Chore - Convert Maven build to Gradle #35

hhandoko opened this issue Dec 21, 2016 · 6 comments

Comments

@hhandoko
Copy link
Owner

Context

Whilst Maven is a mature and capable product, Gradle provides feature parity (in regards with this project) with a more concise and readable syntax.


Definition of Done

Project is build, tested, and deployed via Gradle.

@hhandoko hhandoko added the task label Dec 21, 2016
@hhandoko hhandoko added this to the cassandra-migration-0.10 milestone Dec 21, 2016
@hhandoko hhandoko self-assigned this Dec 21, 2016
@hhandoko hhandoko removed this from the cassandra-migration-0.10 milestone Dec 22, 2016
@hhandoko
Copy link
Owner Author

Encountered various issues with Gradle in Travis CI. Will close this chore and perhaps revisit / retry it in the future (but put it as low priority):

  • Java 1.7 target reported compilation error due to Java version in dependent libraries
  • Embedded Cassandra with OracleJDK 1.8 reported start method error
  • DSE Community and Apache Cassandra with Oracle JDK 1.8 never fully completed integration test

@hhandoko hhandoko reopened this Dec 23, 2016
@hhandoko
Copy link
Owner Author

Reopening this as it warrants further investigation, could be just Gradle configuration issues.

Reference:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.5"
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.11"
    }
}

plugins {
    id 'idea'
    id 'net.researchgate.release' version '2.4.1'
}

group = 'com.builtamont'
version = '0.10-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

description = """Cassandra Migration"""

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'signing'

sourceCompatibility = 1.7
targetCompatibility = 1.7

compileJava.options.fork = false

idea {
  module {
    downloadJavadoc = true
    downloadSources = true
  }
}

sourceSets {
    itest {
        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output

        kotlin.srcDirs += 'src/itest/java'
        java.srcDirs += 'src/itest/java'
        resources.srcDirs += 'src/itest/resources'
    }
}

configurations {
    itestCompile.extendsFrom testCompile
    itestRuntime.extendsFrom testRuntime
}

task itest(type: Test) {
    testClassesDir = sourceSets.itest.output.classesDir
    classpath = sourceSets.itest.runtimeClasspath

    // NOTE: Not needed, but shows which test has run
    //       as each integration test case run can be slow
    testLogging {
        events "passed", "skipped", "failed"
    }
}

task javadocJar(type: Jar) {
    classifier = 'javadoc'
    from javadoc
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version:'1.0.5'
    compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.21'
    compile group: 'commons-logging', name: 'commons-logging', version:'1.2'
    compile group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version:'3.0.0'

    testCompile group: 'org.slf4j', name: 'slf4j-simple', version:'1.7.21'
    testCompile group: 'junit', name: 'junit', version:'4.12'
    testCompile group: 'org.mockito', name: 'mockito-core', version:'1.10.19'
    testCompile group: 'com.nhaarman', name: 'mockito-kotlin', version:'1.0.1'
    testCompile group: 'org.hamcrest', name: 'hamcrest-junit', version:'2.0.0.0'
    testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version:'1.16.0'
    testCompile(group: 'org.cassandraunit', name: 'cassandra-unit', version:'3.0.0.1') {
        exclude(module: 'slf4j-log4j12')
        exclude(module: 'logback-core')
        exclude(module: 'logback-classic')
    }
    testCompile group: 'com.google.guava', name: 'guava', version:'19.0'
    testCompile group: 'io.kotlintest', name: 'kotlintest', version:'1.3.5'
    testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit', version:'1.0.5'

    itestCompile sourceSets.main.output
    itestCompile configurations.testCompile
    itestCompile sourceSets.test.output
    itestRuntime configurations.testRuntime
}

check {
    dependsOn itest
}

artifacts {
    archives javadocJar, sourcesJar
}

uploadArchives {
    repositories {
        mavenDeployer {
            def ossrhUsername = System.getenv('SONATYPE_USERNAME')
            def ossrhPassword = System.getenv('SONATYPE_PASSWORD')

            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            pom.project {
                name 'Cassandra Migration'
                packaging 'jar'
                description 'Database migration tool for Apache Cassandra / DataStax Enterprise'
                url 'https://github.com/builtamont-oss/cassandra-migration'

                scm {
                    url 'https://github.com/builtamont-oss/cassandra-migration'
                    connection 'scm:git:https://github.com/builtamont-oss/cassandra-migration.git'
                    developerConnection 'scm:git:https://github.com/builtamont-oss/cassandra-migration.git'
                }

                licenses {
                    license {
                        name 'The Apache License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }

                developers {
                    developer {
                        id 'hhandoko'
                        name 'Herdy Handoko'
                        url 'http://github.com/hhandoko'
                    }
                }
            }
        }
    }
}

build {
    afterReleaseBuild.dependsOn uploadArchives
}

signing {
    required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
    sign configurations.archives
}

release {
    failOnPublishNeeded = false
}

@hhandoko
Copy link
Owner Author

Was able to reproduce the Java 1.7 issue (with Azul Zulu 1.7 JDK). The root cause seems to be the cassandra-unit library's dependency on Java 1.8.

Why did Maven test work and not Gradle?

com.builtamont.cassandra.migration.ApiMigrationIT > classMethod FAILED
    java.lang.UnsupportedClassVersionError: org/apache/cassandra/io/util/FileUtils : Unsupported major.minor version 52.0

com.builtamont.cassandra.migration.ApiMigrationIT > classMethod FAILED
    java.lang.UnsupportedClassVersionError: org/apache/cassandra/config/DatabaseDescriptor : Unsupported major.minor version 52.0

com.builtamont.cassandra.migration.BaseKIT > initializationError FAILED
    java.lang.UnsupportedClassVersionError: org/apache/cassandra/io/util/FileUtils
        at org.cassandraunit.utils.EmbeddedCassandraServerHelper.rmdir(EmbeddedCassandraServerHelper.java:269)
        at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:83)
        at com.builtamont.cassandra.migration.BaseKIT.beforeAll(BaseKIT.kt:89)

com.builtamont.cassandra.migration.CassandraMigrationApiKIT > initializationError FAILED
    java.lang.UnsupportedClassVersionError: org/apache/cassandra/io/util/FileUtils

com.builtamont.cassandra.migration.CassandraMigrationCommandLineKIT > initializationError FAILED
    java.lang.UnsupportedClassVersionError: org/apache/cassandra/io/util/FileUtils

com.builtamont.cassandra.migration.internal.command.BaselineKIT > initializationError FAILED
    java.lang.UnsupportedClassVersionError: org/apache/cassandra/io/util/FileUtils
Gradle Test Executor 1 finished executing tests.

com.builtamont.cassandra.migration.internal.command.ValidateKIT > initializationError FAILED
    java.lang.UnsupportedClassVersionError: org/apache/cassandra/io/util/FileUtils

@hhandoko
Copy link
Owner Author

Narrowed down the cause, it seems system properties are not read from -Dcassandra.migration JVM args when passed to gradlew in /scripts/verify.sh.

@hhandoko
Copy link
Owner Author

Unsupported JVM version error fixed, next issue identified is to publish JAR with dependencies for use in integration test.

@hhandoko hhandoko added the frozen label Feb 1, 2017
@hhandoko
Copy link
Owner Author

hhandoko commented Mar 7, 2017

Merged latest master into the branch. test context work, however both command-line integration test fails in itest context. Needs further investigation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant