Skip to content

Commit

Permalink
Refactor build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Sep 14, 2023
1 parent e6ccc9e commit 011d67b
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 173 deletions.
53 changes: 14 additions & 39 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- created

env:
JAVA_VERSION: '11'
JAVA_VERSION: '17'
JAVA_DISTRIBUTION: 'microsoft'

jobs:
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Test
run: ./gradlew check

shadow_jar:
build:
needs: test
runs-on: ubuntu-latest
steps:
Expand All @@ -39,13 +39,13 @@ jobs:
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Build JAR
run: ./gradlew shadowJar
- name: Persist JAR Artifact
- name: Build
run: ./gradlew build
- name: Persist JAR Artifacts
uses: actions/upload-artifact@v3
with:
name: jar
path: build/libs/stellar-sdk.jar
name: libs
path: build/libs/*.jar

javadoc:
needs: test
Expand All @@ -66,27 +66,8 @@ jobs:
name: javadoc
path: javadoc

javadoc_jar:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Generate javadocJar
run: ./gradlew javadocJar
- name: Persist javadocJar
uses: actions/upload-artifact@v3
with:
name: javadoc_jar
path: build/libs/stellar-sdk-javadoc.jar

android-test:
needs: shadow_jar
needs: build
runs-on: macos-13
name: android-test (api ${{ matrix.emulator.api-level }})
strategy:
Expand All @@ -104,11 +85,11 @@ jobs:
- name: Download JAR Artifact
uses: actions/download-artifact@v2
with:
name: jar
name: libs
path: android_test/app/libs/
- uses: actions/setup-java@v3
with:
java-version: 17 # TODO: Android Gradle plugin requires Java 11, consider replacing other parts with Java 17.
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
Expand All @@ -121,7 +102,7 @@ jobs:
profile: 'pixel_2'

deploy:
needs: [ javadoc, shadow_jar, javadoc_jar ] # TODO: add android-test when it is stable.
needs: [ build, javadoc ] # TODO: add android-test when it is stable.
permissions:
contents: write
if: github.event_name == 'release' && github.event.action == 'created'
Expand All @@ -132,26 +113,20 @@ jobs:
- name: Download JAR Artifact
uses: actions/download-artifact@v2
with:
name: jar
path: jar
name: libs
path: libs
- name: Download Java Documentation
uses: actions/download-artifact@v2
with:
name: javadoc
path: javadoc
- name: Download javadocJar
uses: actions/download-artifact@v2
with:
name: javadoc_jar
path: javadoc_jar
- name: Archive Documentation
run: tar -czf stellar-sdk-javadoc.tar.gz javadoc
- name: Upload artifacts to GitHub Release
uses: softprops/action-gh-release@v1
with:
files: |
jar/stellar-sdk.jar
javadoc_jar/stellar-sdk-javadoc.jar
libs/*.jar
stellar-sdk-javadoc.tar.gz
- name: Upload Documentation to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
126 changes: 0 additions & 126 deletions build.gradle

This file was deleted.

149 changes: 149 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
plugins {
id("java")
id("java-library")
id("maven-publish")
id("project-report")
id("com.diffplug.spotless") version "6.21.0"
id("com.github.ben-manes.versions") version "0.48.0"
id("io.freefair.lombok") version "8.3"
}

group = "stellar"
version = "0.41.0-beta.3"

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

spotless {
java {
importOrder("java", "javax", "org.stellar")
removeUnusedImports()
googleJavaFormat()
}
}

repositories {
mavenCentral()
}

dependencies {
val okhttpVersion = "4.11.0"

implementation("com.squareup.okhttp3:okhttp:${okhttpVersion}")
implementation("com.squareup.okhttp3:okhttp-sse:${okhttpVersion}")
implementation("com.moandjiezana.toml:toml4j:0.7.2")
implementation("com.google.code.gson:gson:2.10.1")
implementation("net.i2p.crypto:eddsa:0.3.0")
implementation("commons-codec:commons-codec:1.16.0")

testImplementation("org.mockito:mockito-core:5.5.0")
testImplementation("com.squareup.okhttp3:mockwebserver:${okhttpVersion}")
testImplementation("junit:junit:4.13.2")
testImplementation("org.junit.vintage:junit-vintage-engine:5.10.0")
}

tasks {
test {
useJUnitPlatform()
}

jar {
manifest {
attributes["Implementation-Title"] = "stellar-sdk"
attributes["Implementation-Version"] = version
}
archiveFileName = "stellar-sdk.jar"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

val uberJar by creating(Jar::class) {
manifest {
attributes["Implementation-Title"] = "stellar-sdk"
attributes["Implementation-Version"] = version
}
archiveClassifier = "uber"
archiveFileName = "stellar-sdk-uber.jar"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(sourceSets.main.get().output)
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}


val javadocJar by creating(Jar::class) {
manifest {
attributes["Implementation-Title"] = "stellar-sdk"
attributes["Implementation-Version"] = version
}
archiveClassifier = "javadoc"
archiveFileName = "stellar-sdk-javadoc.jar"
dependsOn(javadoc)
from(javadoc.get().destinationDir)
}

javadoc {
destinationDir = file("javadoc")
isFailOnError = false
exclude("org/stellar/sdk/xdr/**")
options {
// https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
this as StandardJavadocDocletOptions
isSplitIndex = true
memberLevel = JavadocMemberLevel.PUBLIC
encoding = "UTF-8"
}
}

register<Copy>("updateGitHook") {
from("scripts/pre-commit.sh") { rename { it.removeSuffix(".sh") } }
into(".git/hooks")
doLast {
file(".git/hooks/pre-commit").setExecutable(true)
}
}

compileJava {
options.encoding = "UTF-8"
}

compileTestJava {
options.encoding = "UTF-8"
}
}

artifacts {
archives(tasks.jar)
archives(tasks["uberJar"])
archives(tasks["javadocJar"])
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifact(tasks["uberJar"])
artifact(tasks["javadocJar"])
pom {
name.set("java-stellar-sdk")
description.set("The Java Stellar SDK library provides APIs to build transactions and connect to Horizon and Soroban-RPC server.")
url.set("https://github.com/stellar/java-stellar-sdk")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://github.com/stellar/java-stellar-sdk/blob/master/LICENSE")
}
}
developers {
developer {
id.set("stellar")
name.set("Stellar Development Foundation")
}
}
}
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit 011d67b

Please sign in to comment.