8000 Migrate to Gradle DSL as a build tool by Pazus · Pull Request #73 · utPLSQL/utPLSQL-java-api · GitHub
[go: up one dir, main page]

Skip to content

Migrate to Gradle DSL as a build tool #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Maven
target/
build
.gradle
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
Expand All @@ -18,3 +20,4 @@ buildNumber.properties

#Exclude CoverageHTMLReporter resources as they are managed by maven
src/main/resources/CoverageHTMLReporter/
/gradle.properties
30 changes: 17 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ env:
- DOCKER_CFG=$HOME/.docker
- DOCKER_REPO="utplsqlv3/oracledb"
- CACHE_DIR=$HOME/.cache
- MAVEN_HOME=/usr/local/maven
- MAVEN_CFG=$HOME/.m2
- DB_URL="127.0.0.1:1521:XE"
- DB_USER=app
- DB_PASS=app
Expand All @@ -33,30 +31,27 @@ env:
- UTPLSQL_VERSION="develop"
UTPLSQL_FILE="utPLSQL"

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $DOCKER_CFG
- $CACHE_DIR
- $MAVEN_CFG

install:
- bash .travis/maven_cfg.sh
- bash .travis/start_db.sh
- bash .travis/install_utplsql.sh
- bash .travis/install_demo_project.sh

before_script:
- cp .travis/settings.xml $MAVEN_CFG/settings.xml

script:
- mvn verify -B

before_deploy:
- if [ ! -z "$TRAVIS_TAG" ]; then VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=${VERSION}; fi
- ./gradlew check

deploy:
- provider: script
script: mvn clean deploy -DskipTests=true -B -U -DtravisBuildNumber=$TRAVIS_BUILD_NUMBER
script: ./gradlew uploadArchives
skip_cleanup: true
on:
repository: utPLSQL/utPLSQL-java-api
Expand All @@ -65,14 +60,23 @@ deploy:
condition: "${TRAVIS_JOB_NUMBER} =~ \\.1$"

- provider: script
script: mvn clean deploy -DskipTests=true -B -U -DtravisBuildNumber=$TRAVIS_BUILD_NUMBER
script: ./gradlew uploadArchives -PtravisBuildNumber=$TRAVIS_BUILD_NUMBER
skip_cleanup: true
on:
repository: utPLSQL/utPLSQL-java-api
branch: develop
# Use only first job "#xxx.1" to publish artifacts
condition: "${TRAVIS_JOB_NUMBER} =~ \\.1$"

- provider: script
script: ./gradlew uploadArchives -PtravisBuildNumber=$TRAVIS_BUILD_NUMBER
skip_cleanup: true
on:
repository: utPLSQL/utPLSQL-java-api
branch: gradle-dsl-migration
# Use only first job "#xxx.1" to publish artifacts
condition: "${TRAVIS_JOB_NUMBER} =~ \\.1$"

notifications:
slack:
rooms:
Expand Down
48 changes: 15 additions & 33 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,32 @@ https://maven.apache.org/install.html

### Oracle Maven Repository
The library uses OJDBC Driver to connect to the database, it's added as a maven dependency. To be able to download the Oracle dependencies, you need to configure your access to Oracle's Maven Repository:
Create file `gradle.properties` in the root directory of the repository and place OTN credentials there:
```properties
ORACLE_OTN_USER=user@email.com
ORACLE_OTN_PASSWORD=password
```

http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9010
After configuring your access to Oracle's Maven repository, you will be able to successfully build this API by disabling integration tests.

*Sections 6.1 and 6.5 are the more important ones, and the only ones you need if you're using the latest Maven version.*
```bash
./gradlew build -x intTest
```

### Local database with utPLSQL and utPLSQL-demo-project

To usefully contribute you'll have to setup a local database with installed [latest utPLSQL v3](https://github.com/utPLSQL/utPLSQL) and [utPLSQL-demo-project](https://github.com/utPLSQL/utPLSQL-demo-project).
The demo-project will serve as your test user. See .travis.yml to see an example on how it can be installed.
By default tests are executed against `app/app` user of `localhost:1521/XE database`.

### Maven settings for utPLSQL-local profile

utPLSQL-java-api comes with a preconfigured profile "utPLSQL-local". This profile uses properties to set the correct
environment variables for DB_URL, DB_USER and DB_PASS which is needed to run the integration tests.
You can set these properties by adding the following to your Maven settings.xml:

```xml
<settings>
<!-- ... -->
<profiles>
<profile>
<id>utPLSQL-local</id>
<properties>
<dbUrl>localhost:1521/XE</dbUrl>
<dbUser>app</dbUser>
<dbPass>app</dbPass>
</properties>
</profile>
</profiles>

<activeProfiles>
<activeProfile>utPLSQL-local</activeProfile>
</activeProfiles>
</settings>
```

After configuring your access to Oracle's Maven repository, you will be able to successfully build this API.
If you want to run tests against another database you may set `DB_URL`, `DB_USER`, `DB_PASS` environment variables.

When you have local database set up you can run the complete build including integration tests by executing
```bash
cd utPLSQL-java-api
mvn clean package install
./gradlew build
```

### Skip the local database part

If you want to skip the local database part, just run ``mvn clean package install -DskipTests``.
You will still be able to run ``mvn test`` because integration tests are run in the ``verify``-phase.
If you want to skip the local database part, just run ``./gradlew test``.
You will be able to run ``./gradle test`` because integration tests are executed in the separate ``intTest`` task as part of overall ``check``.
166 changes: 166 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import de.undercouch.gradle.tasks.download.Download
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

val deployerJars by configurations.creating

group = "org.utplsql"
val mavenArtifactId = "java-api"
version = "3.1.3-SNAPSHOT"

val coverageResourcesVersion = "1.0.1"
val ojdbcVersion = "12.2.0.1"

plugins {
`java-library`
`maven-publish`
maven
id("de.undercouch.download") version "3.4.3"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

// In this section you declare where to find the dependencies of your project
repositories {
maven {
url = uri("https://www.oracle.com/content/secure/maven/content")
credentials {
// you may set this properties using gradle.properties file in the root of the project or in your GRADLE_HOME
username = if (project.hasProperty("ORACLE_OTN_USER")) project.property("ORACLE_OTN_USER") as String? else System.getenv("ORACLE_OTN_USER")
password = if (project.hasProperty("ORACLE_OTN_PASSWORD")) project.property("ORACLE_OTN_PASSWORD") as String? else System.getenv("ORACLE_OTN_PASSWORD")
}
}
mavenCentral()
}

dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api("com.google.code.findbugs:jsr305:3.0.2")

// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation("org.slf4j:slf4j-api:1.7.25")
implementation("com.oracle.jdbc:ojdbc8:$ojdbcVersion") {
exclude(group = "com.oracle.jdbc")
}
implementation("com.oracle.jdbc:orai18n:$ojdbcVersion")

// Use Jupiter test framework
testImplementation("org.junit.jupiter:junit-jupiter:5.4.0")
testImplementation("org.hamcrest:hamcrest:2.1")
deployerJars("io.packagecloud.maven.wagon:maven-packagecloud-wagon:0.0.6")
}

tasks {
test {
useJUnitPlatform()
exclude("**/*IT.class")
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
showStackTraces = true
}
}

val intTest = create<Test>("intTest") {
dependsOn(test)
doFirst {
environment("DB_URL", System.getenv("DB_URL") ?: "localhost:1521/XE")
environment("DB_USER", System.getenv("DB_USER") ?: "app")
environment("DB_PASS", System.getenv("DB_PASS") ?: "app")
}
useJUnitPlatform()
include("**/*IT.class")
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
showStackTraces = true
showStandardStreams = true
}
}

// add integration tests to the whole check
named("check") {
dependsOn(intTest)
}

val coverageResourcesDirectory = "${project.buildDir}/resources/main/CoverageHTMLReporter"
val coverageResourcesZip = "${project.buildDir}/utPLSQL-coverage-html-$coverageResourcesVersion.zip"

// download Coverage Resources from web
val downloadResources = create<Download>("downloadCoverageResources") {
src("https://codeload.github.com/utPLSQL/utPLSQL-coverage-html/zip/$coverageResourcesVersion")
dest(File(coverageResourcesZip))
overwrite(true)
}

withType<ProcessResources> {
dependsOn(downloadResources)

val properties = project.properties.toMutableMap()
properties.putIfAbsent("travisBuildNumber", System.getenv("TRAVIS_BUILD_NUMBER") ?: "local")
expand(properties)

doLast {
copy {
// extract assets folder only from downloaded archive
// https://github.com/gradle/gradle/pull/8494
from(zipTree(coverageResourcesZip)) {
include("*/assets/**")
eachFile {
relativePath = RelativePath(true, *relativePath.segments.drop(2).toTypedArray()) // <2>
}
includeEmptyDirs = false
}
into(coverageResourcesDirectory)
}
}
}

withType<Jar> {
dependsOn("generatePomFileForMavenPublication")
manifest {
attributes(
"Built-By" to System.getProperty("user.name"),
"Created-By" to "Gradle ${gradle.gradleVersion}",
"Build-Jdk" to "${System.getProperty("os.name")} ${System.getProperty("os.arch")} ${System.getProperty("os.version")}"
)
}
into("META-INF/maven/${project.group}/$mavenArtifactId") {
from("$buildDir/publications/maven")
rename(".*", "pom.xml")
}

}

named<Upload>("uploadArchives") {
repositories.withGroovyBuilder {
"mavenDeployer" {
setProperty("configuration", deployerJars)
"repository"("url" to "packagecloud+https://packagecloud.io/utPLSQL/utPLSQL-java-api") {
"authentication"("password" to System.getenv("PACKAGECLOUD_TOKEN"))
}
}
}
}
}

publishing {
publications {
create<MavenPublication>("maven") {
artifactId = mavenArtifactId
pom {
name.set("utPLSQL-java-api")
url.set("https://github.com/utPLSQL/utPLSQL-java-api")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
}
from(components["java"])
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
0