diff --git a/.github/workflows/tests.yml b/.github/workflows/hndrs-gradle-check.yml similarity index 72% rename from .github/workflows/tests.yml rename to .github/workflows/hndrs-gradle-check.yml index ea9b8bd..fd9dde2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/hndrs-gradle-check.yml @@ -1,31 +1,29 @@ -name: Tests +name: gradle # Controls when the action will run. on: - pull_request: branches: [ main ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - test: + check: runs-on: ubuntu-latest steps: - - name: Git Checkout + - name: git checkout uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Setup Java + - name: setup java uses: actions/setup-java@v1 with: - java-version: '15' + java-version: '11' - - name: Setup Build Cache + - name: gradle cache uses: actions/cache@v2 with: path: | @@ -34,6 +32,7 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} restore-keys: | ${{ runner.os }}-gradle- - - name: Tests + + - name: test run: | ./gradlew check diff --git a/.github/workflows/hndrs-gradle-publish.yml b/.github/workflows/hndrs-gradle-publish.yml new file mode 100644 index 0000000..83437a6 --- /dev/null +++ b/.github/workflows/hndrs-gradle-publish.yml @@ -0,0 +1,44 @@ +name: gradle + +# Controls when the action will run. +on: + push: + tags: + - v* + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: git checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: setup java + uses: actions/setup-java@v1 + with: + java-version: '11' + + - name: setup build cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: publish + env: + SONATYPE_USER: ${{ secrets.SONATYPE_USER }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + run: | + ./gradlew publish diff --git a/.github/workflows/hndrs-gradle-sonar.yml b/.github/workflows/hndrs-gradle-sonar.yml new file mode 100644 index 0000000..13ac6e9 --- /dev/null +++ b/.github/workflows/hndrs-gradle-sonar.yml @@ -0,0 +1,51 @@ +name: gradle + +# Controls when the action will run. +on: + push: + branches: + - master + pull_request: + branches: [ main ] + types: [ opened, synchronize, reopened ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + analyse: + runs-on: ubuntu-latest + + steps: + - name: git checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: setup java + uses: actions/setup-java@v1 + with: + java-version: '11' + + - name: gradle cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: sonar cache + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: analyse + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew check jacocoTestReport sonarqube --info diff --git a/build.gradle.kts b/build.gradle.kts index aae4b3c..bf96646 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,5 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -object Versions { - const val KOTLIN_VERSION = "1.4.30" -} - buildscript { repositories { mavenCentral() @@ -14,27 +10,40 @@ buildscript { } } +val springBootDependencies: String by extra +val kotlinVersion: String by extra + plugins { - id("org.sonarqube").version("3.0") - `maven-publish` - id("io.spring.dependency-management") version "1.0.10.RELEASE" - kotlin("jvm").version("1.4.30") - kotlin("plugin.spring").version("1.4.30") - kotlin("kapt").version("1.4.30") + id("org.sonarqube").version("3.1.1") + id("io.spring.dependency-management") + kotlin("jvm") + kotlin("plugin.spring") + kotlin("kapt") id("java") id("maven-publish") id("idea") + id("signing") + id("io.hndrs.publishing-info").version("1.0.0") } -group = "com.elvah.auth" +group = "io.hndrs" version = rootProject.file("version.txt").readText().trim() -java.sourceCompatibility = JavaVersion.VERSION_15 -java.targetCompatibility = JavaVersion.VERSION_15 +java.sourceCompatibility = JavaVersion.VERSION_11 +java.targetCompatibility = JavaVersion.VERSION_11 repositories { mavenCentral() } +sonarqube { + properties { + property("sonar.projectKey", "hndrs_jsonapi-spring-boot-starter") + property("sonar.organization", "hndrs") + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.exclusions", "**/sample/**") + } +} + subprojects { apply(plugin = "kotlin") @@ -46,16 +55,32 @@ subprojects { apply(plugin = "jacoco") apply(plugin = "propdeps") apply(plugin = "propdeps-idea") - - + apply(plugin = "signing") + apply(plugin = "io.hndrs.publishing-info") + + publishingInfo { + url = "https://github.com/hndrs/jsonapi-spring-boot-starter" + license = io.hndrs.gradle.plugin.License( + "https://github.com/hndrs/jsonapi-spring-boot-starter/blob/main/LICENSE", + "MIT License" + ) + developers = listOf( + io.hndrs.gradle.plugin.Developer("marvinschramm", "Marvin Schramm", "marvin.schramm@gmail.com") + ) + organization = io.hndrs.gradle.plugin.Organization("hndrs", "https://oss.hndrs.io") + scm = io.hndrs.gradle.plugin.Scm( + "scm:git:git://github.com/hndrs/jsonapi-spring-boot-starter", + "https://github.com/hndrs/jsonapi-spring-boot-starter" + ) + } dependencyManagement { resolutionStrategy { cacheChangingModulesFor(0, "seconds") } imports { - mavenBom("org.springframework.boot:spring-boot-dependencies:2.4.2") { - bomProperty("kotlin.version", Versions.KOTLIN_VERSION) + mavenBom("org.springframework.boot:spring-boot-dependencies:$springBootDependencies") { + bomProperty("kotlin.version", kotlinVersion) } } } @@ -81,7 +106,7 @@ subprojects { tasks.withType { kotlinOptions { freeCompilerArgs = listOf("-Xjsr305=strict") - jvmTarget = "15" + jvmTarget = "11" } } @@ -91,10 +116,19 @@ subprojects { from(sourceSets["main"].allSource) } + if (project.name != "sample") { + publishing { repositories { - + maven { + name = "release" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2") + credentials { + username = System.getenv("SONATYPE_USER") + password = System.getenv("SONATYPE_PASSWORD") + } + } } publications { create(project.name) { @@ -104,9 +138,19 @@ subprojects { groupId = rootProject.group as? String artifactId = project.name version = "${rootProject.version}${project.findProperty("version.appendix") ?: ""}" + pom { + + } + } + } + val signingKey: String? = System.getenv("SIGNING_KEY") + val signingPassword: String? = System.getenv("SIGNING_PASSWORD") + if (signingKey != null && signingPassword != null) { + signing { + useInMemoryPgpKeys(groovy.json.StringEscapeUtils.unescapeJava(signingKey), signingPassword) + sign(publications[project.name]) } } - } } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..668e04f --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +kotlinVersion=1.4.30 +springDependencyManagement=1.0.11.RELEASE +springBootDependencies=2.4.2 diff --git a/settings.gradle.kts b/settings.gradle.kts index d49652f..75f2ee9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,3 +8,19 @@ project(":spring-json-api-starter").projectDir = File("spring-json-api-starter") include("sample") project(":sample").projectDir = File("sample") + +pluginManagement { + val kotlinVersion: String by settings + val springDependencyManagement: String by settings + println("Settings ${settings.extra.properties}") + plugins { + id("io.spring.dependency-management").version(springDependencyManagement) + kotlin("jvm").version(kotlinVersion) + kotlin("plugin.spring").version(kotlinVersion) + kotlin("kapt").version(kotlinVersion) + id("maven-publish") + id("idea") + } + repositories { + } +} diff --git a/spring-json-api-starter/build.gradle.kts b/spring-json-api-starter/build.gradle.kts index cadd4be..79f24d4 100644 --- a/spring-json-api-starter/build.gradle.kts +++ b/spring-json-api-starter/build.gradle.kts @@ -1,4 +1,10 @@ dependencies { api(project(":spring-json-api")) + api(group = "org.springframework.boot", name = "spring-boot-autoconfigure") + + annotationProcessor(group = "org.springframework.boot", name = "spring-boot-configuration-processor") + kapt(group = "org.springframework.boot", name = "spring-boot-configuration-processor") + testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-test") + testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-web") } diff --git a/spring-json-api-starter/src/test/kotlin/io/hndrs/api/autoconfigure/JsonApiAutoConfigurationTest.kt b/spring-json-api-starter/src/test/kotlin/io/hndrs/api/autoconfigure/JsonApiAutoConfigurationTest.kt index c01c4d7..a5ae519 100644 --- a/spring-json-api-starter/src/test/kotlin/io/hndrs/api/autoconfigure/JsonApiAutoConfigurationTest.kt +++ b/spring-json-api-starter/src/test/kotlin/io/hndrs/api/autoconfigure/JsonApiAutoConfigurationTest.kt @@ -17,6 +17,7 @@ internal class JsonApiAutoConfigurationTest { .withConfiguration( AutoConfigurations.of(JsonApiAutoConfiguration::class.java) ).run { + Assertions.assertNotNull(it.getBean(ExceptionHandler::class.java)) Assertions.assertNotNull(it.getBean(ResponseAdvice::class.java)) } diff --git a/spring-json-api/build.gradle.kts b/spring-json-api/build.gradle.kts index cd8e9d2..dbeda30 100644 --- a/spring-json-api/build.gradle.kts +++ b/spring-json-api/build.gradle.kts @@ -1,3 +1,3 @@ dependencies { - api(group = "org.springframework.boot", name = "spring-boot-starter-web") + optional(group = "org.springframework.boot", name = "spring-boot-starter-web") }