diff --git a/.ci b/.ci new file mode 160000 index 0000000..d71dac0 --- /dev/null +++ b/.ci @@ -0,0 +1 @@ +Subproject commit d71dac0ff32ba2387585070724b8d441aec0ae7c diff --git a/.ci-local/deploy-maven-central.conf b/.ci-local/deploy-maven-central.conf new file mode 100644 index 0000000..6e7a8a7 --- /dev/null +++ b/.ci-local/deploy-maven-central.conf @@ -0,0 +1,4 @@ +# +# The presence of this file specifies that the CI process should push artifacts to Maven Central. +# The contents of the file are otherwise ignored. +# diff --git a/.ci-local/tag-prefix.conf b/.ci-local/tag-prefix.conf new file mode 100644 index 0000000..69a5fac --- /dev/null +++ b/.ci-local/tag-prefix.conf @@ -0,0 +1,8 @@ +org.thepalaceproject.deploytest- + +# +# The first line of this file specifies a prefix to use to generate tags when releases are tagged +# by CI. Everything else in the file is ignored. +# +# The final name of the tag will be ${TAG_PREFIX}-${VERSION_NAME}. +# diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..63b021c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "gitsubmodule" + directory: "/" + schedule: + interval: "daily" + diff --git a/.github/workflows/android-main.yml b/.github/workflows/android-main.yml new file mode 100644 index 0000000..f7acb1f --- /dev/null +++ b/.github/workflows/android-main.yml @@ -0,0 +1,33 @@ +name: Android CI (Authenticated) + +on: + push: + branches: [ main, release/* ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Checkout submodules + run: git submodule update --init --recursive + - name: set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + - name: Build + env: + MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + MAVEN_CENTRAL_STAGING_PROFILE_ID: ${{ secrets.MAVEN_CENTRAL_STAGING_PROFILE_ID }} + MAVEN_CENTRAL_SIGNING_KEY_ID: ${{ secrets.MAVEN_CENTRAL_SIGNING_KEY_ID }} + CI_GITHUB_ACCESS_TOKEN: ${{ secrets.CI_GITHUB_ACCESS_TOKEN }} + run: .ci/ci-main.sh normal + - name: Upload test report + uses: actions/upload-artifact@v4 + if: ${{ always() }} + with: + name: junit-test-report + path: ./org.thepalaceproject.deploytest.tests/build/reports/tests/testDebugUnitTest diff --git a/.github/workflows/android-pr.yml b/.github/workflows/android-pr.yml new file mode 100644 index 0000000..86a9b1f --- /dev/null +++ b/.github/workflows/android-pr.yml @@ -0,0 +1,27 @@ +name: Android CI (Pull Requests) + +on: + pull_request: + branches: [ main, feature/* ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Checkout submodules + run: git submodule update --init --recursive + - name: set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + - name: Build PR + run: .ci/ci-main.sh pull-request + - name: Upload test report + uses: actions/upload-artifact@v4 + if: ${{ always() }} + with: + name: junit-test-report + path: ./org.thepalaceproject.deploytest.tests/build/reports/tests/testDebugUnitTest diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml new file mode 100644 index 0000000..526240b --- /dev/null +++ b/.github/workflows/android-release.yml @@ -0,0 +1,25 @@ +name: Create Release +on: workflow_dispatch +jobs: + create-release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Checkout submodules + run: git submodule update --init --recursive + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + - name: Finish release + run: .ci/ci-release-finish.sh + - name: Build + env: + MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + MAVEN_CENTRAL_STAGING_PROFILE_ID: ${{ secrets.MAVEN_CENTRAL_STAGING_PROFILE_ID }} + MAVEN_CENTRAL_SIGNING_KEY_ID: ${{ secrets.MAVEN_CENTRAL_SIGNING_KEY_ID }} + CI_GITHUB_ACCESS_TOKEN: ${{ secrets.CI_GITHUB_ACCESS_TOKEN }} + run: .ci/ci-main.sh normal diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7985796 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# +# Android Studio 2.2.3 Defaults +# + +**/build +*.iml +.DS_Store +.externalNativeBuild +.gradle +.idea +/captures +/local.properties + +# Ignore .so files +**/jniLibs + +# Certificates and api(Keys) +*.jks + +# Backup files +*~ + +# Misc +.env diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..17b666b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".ci"] + path = .ci + url = https://www.github.com/ThePalaceProject/android-ci diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..b44be02 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,848 @@ +import com.android.build.api.dsl.ApplicationExtension +import com.android.build.gradle.LibraryExtension +import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download +import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Verify +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension + +val gradleVersionRequired = "8.2.1" +val gradleVersionReceived = gradle.gradleVersion + +if (gradleVersionRequired != gradleVersionReceived) { + throw GradleException( + "Gradle version $gradleVersionRequired is required to run this build. You are using Gradle $gradleVersionReceived", + ) +} + +plugins { + signing + + id("org.jetbrains.kotlin.jvm") + .version("1.9.0") + .apply(false) + + id("org.jetbrains.kotlin.android") + .version("1.9.0") + .apply(false) + + /* + * The AndroidX plugin for navigation (including view binding generation). + * + * https://developer.android.com/jetpack/androidx/releases/navigation + */ + + id("androidx.navigation.safeargs.kotlin") + .version("2.7.1") + .apply(false) + + id("com.android.library") + .version("8.1.0") + .apply(false) + + id("com.android.application") + .version("8.1.0") + .apply(false) + + /* + * Android Junit5 plugin. Required to run JUnit 5 tests on Android projects. + * + * https://github.com/mannodermaus/android-junit5 + */ + + id("de.mannodermaus.android-junit5") + .version("1.9.3.0") + .apply(false) + + /* + * Download plugin. Used to fetch artifacts such as Scando during the build. + * + * https://plugins.gradle.org/plugin/de.undercouch.download + */ + + id("de.undercouch.download") + .version("5.4.0") + .apply(false) + + /* + * https://developers.google.com/android/guides/google-services-plugin + */ + + id("com.google.gms.google-services") + .version("4.3.15") + .apply(false) + + /* + * https://firebase.google.com/docs/crashlytics/get-started?platform=android + */ + + id("com.google.firebase.crashlytics") + .version("2.9.9") + .apply(false) + + id("maven-publish") +} + +/* + * The various paths used during the build. + */ + +val palaceRootBuildDirectory = + "$rootDir/build" +val palaceDeployDirectory = + "$palaceRootBuildDirectory/maven" +val palaceScandoJarFile = + "$rootDir/scando.jar" +val palaceKtlintJarFile = + "$rootDir/ktlint.jar" + +/** + * Convenience functions to read strongly-typed values from property files. + */ + +fun property( + project: Project, + name: String, +): String { + return project.extra[name] as String +} + +fun propertyOptional(project: Project, name: String): String? { + val map = project.extra + if (map.has(name)) { + return map[name] as String? + } + return null +} + +fun propertyInt( + project: Project, + name: String, +): Int { + val text = property(project, name) + return text.toInt() +} + +fun propertyBoolean( + project: Project, + name: String, +): Boolean { + val text = property(project, name) + return text.toBooleanStrict() +} + +fun propertyBooleanOptional( + project: Project, + name: String, + defaultValue: Boolean, +): Boolean { + val value = propertyOptional(project, name) ?: return defaultValue + return value.toBooleanStrict() +} + +/** + * Configure Maven publishing. Artifacts are published to a local directory + * so that they can be pushed to Maven Central in one step using brooklime. + */ + +fun configurePublishingFor(project: Project) { + val mavenCentralUsername = + (project.findProperty("mavenCentralUsername") ?: "") as String + val mavenCentralPassword = + (project.findProperty("mavenCentralPassword") ?: "") as String + + val versionName = + property(project, "VERSION_NAME") + val packaging = + property(project, "POM_PACKAGING") + + val publishSources = + propertyBoolean(project, "org.thepalaceproject.build.publishSources") + val enableSigning = + propertyBooleanOptional(project, "org.thepalaceproject.build.enableSigning", true) + + /* + * Create an empty JavaDoc jar. Required for Maven Central deployments. + */ + + val taskJavadocEmpty = + project.task("JavadocEmptyJar", org.gradle.jvm.tasks.Jar::class) { + this.archiveClassifier = "javadoc" + } + + /* + * Create a publication. Note that the name of the publication must be unique across all + * modules, because the broken Gradle signing plugin will create a signing task for each + * one that, in the case of a name conflict, will silently overwrite the previous signing + * task. + */ + + project.publishing { + publications { + create("_${project.name}_MavenPublication") { + groupId = property(project, "GROUP") + artifactId = property(project, "POM_ARTIFACT_ID") + version = versionName + + /* + * https://central.sonatype.org/publish/requirements/#sufficient-metadata + */ + + pom { + name.set(property(project, "POM_NAME")) + description.set(property(project, "POM_DESCRIPTION")) + url.set(property(project, "POM_URL")) + + scm { + connection.set(property(project, "POM_SCM_CONNECTION")) + developerConnection.set(property(project, "POM_SCM_DEV_CONNECTION")) + url.set(property(project, "POM_SCM_URL")) + } + + licenses { + license { + name.set(property(project, "POM_LICENCE_NAME")) + url.set(property(project, "POM_LICENCE_URL")) + } + } + + developers { + developer { + name.set("The Palace Project") + email.set("info@thepalaceproject.org") + organization.set("The Palace Project") + organizationUrl.set("https://thepalaceproject.org/") + } + } + } + + artifact(taskJavadocEmpty) + + from( + when (packaging) { + "jar" -> { + project.components["java"] + } + + "aar" -> { + project.components["release"] + } + + "apk" -> { + project.components["release"] + } + + else -> { + throw java.lang.IllegalArgumentException( + "Cannot set up publishing for packaging type $packaging", + ) + } + }, + ) + } + } + + repositories { + maven { + name = "Directory" + url = uri(palaceDeployDirectory) + } + + /* + * Only deploy to the Sonatype snapshots repository if the current version is a + * snapshot version. + */ + + if (versionName.endsWith("-SNAPSHOT")) { + maven { + name = "SonatypeCentralSnapshots" + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") + + credentials { + username = mavenCentralUsername + password = mavenCentralPassword + } + } + } + } + } + + /* + * If source publications are disabled in the project properties, it seems that the only + * way to stop the Android plugins from publishing sources is to manually "disable" the + * publication tasks by deleting all of the actions within the tasks, and then specifying + * a dependency on our own task that produces an empty jar file. + */ + + if (!publishSources) { + logger.info("org.thepalaceproject.build.publishSources is false, so source jars are disabled.") + + val taskSourcesEmpty = + project.task("SourcesEmptyJar", org.gradle.jvm.tasks.Jar::class) { + this.archiveClassifier = "sources" + } + + project.tasks.matching { task -> task.name.endsWith("SourcesJar") } + .forEach { task -> + task.actions.clear() + task.dependsOn.add(taskSourcesEmpty) + } + } + + /* + * Configure signing. + */ + + if (enableSigning) { + signing { + useGpgCmd() + sign(project.publishing.publications) + } + } +} + +/* + * A task that cleans up the Maven deployment directory. The "clean" tasks of + * each project are configured to depend upon this task. This prevents any + * deployment of stale artifacts to remote repositories. + */ + +val cleanTask = task("CleanMavenDeployDirectory", Delete::class) { + this.delete.add(palaceDeployDirectory) +} + +/** + * A function to download and verify the Scando jar file. + * + * @return The verification task + */ + +fun createScandoDownloadTask(project: Project): Task { + val scandoVersion = + "1.0.0" + val scandoSHA256 = + "08fba5fc4bc3b5a49d205a4c38356dc8c7e01f4963adb661b67f9d2ed23751ae" + val scandoSource = + "https://repo1.maven.org/maven2/com/io7m/scando/com.io7m.scando.cmdline/$scandoVersion/com.io7m.scando.cmdline-$scandoVersion-main.jar" + + val scandoMakeDirectory = + project.task("ScandoMakeDirectory") { + mkdir(palaceRootBuildDirectory) + } + + val scandoDownload = + project.task("ScandoDownload", Download::class) { + src(scandoSource) + dest(file(palaceScandoJarFile)) + overwrite(true) + this.dependsOn.add(scandoMakeDirectory) + } + + return project.task("ScandoDownloadVerify", Verify::class) { + src(file(palaceScandoJarFile)) + checksum(scandoSHA256) + algorithm("SHA-256") + this.dependsOn(scandoDownload) + } +} + +/** + * A task to execute Scando to analyze semantic versioning. + */ + +fun createScandoAnalyzeTask(project: Project): Task { + val group = + property(project, "GROUP") + val artifactId = + property(project, "POM_ARTIFACT_ID") + val versionCurrent = + property(project, "VERSION_NAME") + val versionPrevious = + property(project, "VERSION_PREVIOUS") + + val oldGroup = + group.replace('.', '/') + val oldPath = + "$oldGroup/$artifactId/$versionPrevious/$artifactId-$versionPrevious.aar" + val oldUrl = + "https://repo1.maven.org/maven2/$oldPath" + + val commandLineArguments: List = arrayListOf( + "java", + "-jar", + palaceScandoJarFile, + "--excludeList", + "${project.rootDir}/VERSIONING.txt", + "--oldJarUri", + oldUrl, + "--oldJarVersion", + versionPrevious, + "--ignoreMissingOld", + "--newJar", + "${project.buildDir}/outputs/aar/$artifactId-debug.aar", + "--newJarVersion", + versionCurrent, + "--textReport", + "${project.buildDir}/scando-report.txt", + "--htmlReport", + "${project.buildDir}/scando-report.html", + ) + + return project.task("ScandoAnalyze", Exec::class) { + commandLine = commandLineArguments + } +} + +/* + * Create a task in the root project that downloads Scando. + */ + +lateinit var scandoDownloadTask: Task + +rootProject.afterEvaluate { + apply(plugin = "de.undercouch.download") + scandoDownloadTask = createScandoDownloadTask(this) +} + +/** + * A function to download and verify the ktlint jar file. + * + * @return The verification task + */ + +fun createKtlintDownloadTask(project: Project): Task { + val ktlintVersion = + "0.50.0" + val ktlintSHA256 = + "c704fbc28305bb472511a1e98a7e0b014aa13378a571b716bbcf9d99d59a5092" + val ktlintSource = + "https://repo1.maven.org/maven2/com/pinterest/ktlint/$ktlintVersion/ktlint-$ktlintVersion-all.jar" + + val ktlintMakeDirectory = + project.task("KtlintMakeDirectory") { + mkdir(palaceRootBuildDirectory) + } + + val ktlintDownload = + project.task("KtlintDownload", Download::class) { + src(ktlintSource) + dest(file(palaceKtlintJarFile)) + overwrite(true) + onlyIfModified(true) + this.dependsOn.add(ktlintMakeDirectory) + } + + return project.task("KtlintDownloadVerify", Verify::class) { + src(file(palaceKtlintJarFile)) + checksum(ktlintSHA256) + algorithm("SHA-256") + this.dependsOn(ktlintDownload) + } +} + +/** + * A task to execute ktlint to check sources. + */ + +val ktlintPatterns: List = arrayListOf( + "*/src/**/*.kt", + "*/build.gradle.kts", + "build.gradle.kts", + "!*/src/test/**", +) + +fun createKtlintCheckTask(project: Project): Task { + val commandLineArguments: ArrayList = arrayListOf( + "java", + "-jar", + palaceKtlintJarFile, + ) + commandLineArguments.addAll(ktlintPatterns) + + return project.task("KtlintCheck", Exec::class) { + commandLine = commandLineArguments + } +} + +/** + * A task to execute ktlint to reformat sources. + */ + +fun createKtlintFormatTask(project: Project): Task { + val commandLineArguments: ArrayList = arrayListOf( + "java", + "-jar", + palaceKtlintJarFile, + "-F", + ) + commandLineArguments.addAll(ktlintPatterns) + + return project.task("KtlintFormat", Exec::class) { + commandLine = commandLineArguments + } +} + +/* + * Create a task in the root project that downloads ktlint. + */ + +lateinit var ktlintDownloadTask: Task + +rootProject.afterEvaluate { + apply(plugin = "de.undercouch.download") + ktlintDownloadTask = createKtlintDownloadTask(this) + + val enableKtlintChecks = + propertyBoolean(this, "org.thepalaceproject.build.enableKtLint") + + if (enableKtlintChecks) { + val checkActual = createKtlintCheckTask(this) + checkActual.dependsOn.add(ktlintDownloadTask) + cleanTask.dependsOn.add(checkActual) + } + + /* + * Create a task that can be used to reformat sources. This is purely for manual execution + * from the command-line, and is not executed otherwise. + */ + + val formatTask = createKtlintFormatTask(this) + formatTask.dependsOn.add(ktlintDownloadTask) +} + +allprojects { + + /* + * Configure the project metadata. + */ + + this.group = + property(this, "GROUP") + this.version = + property(this, "VERSION_NAME") + + val jdkBuild = + propertyInt(this, "org.thepalaceproject.build.jdkBuild") + val jdkBytecodeTarget = + propertyInt(this, "org.thepalaceproject.build.jdkBytecodeTarget") + + /* + * Configure builds and tests for various project types. + */ + + when (extra["POM_PACKAGING"]) { + "pom" -> { + logger.info("Configuring ${this.project} $version as a pom project") + } + + "apk" -> { + logger.info("Configuring ${this.project} $version as an apk project") + + apply(plugin = "com.android.application") + apply(plugin = "org.jetbrains.kotlin.android") + + /* + * Configure the JVM toolchain version that we want to use for Kotlin. + */ + + val kotlin: KotlinAndroidProjectExtension = + this.extensions["kotlin"] as KotlinAndroidProjectExtension + val java: JavaPluginExtension = + this.extensions["java"] as JavaPluginExtension + + kotlin.jvmToolchain(jdkBuild) + java.toolchain.languageVersion.set(JavaLanguageVersion.of(jdkBuild)) + + /* + * Configure the various required Android properties. + */ + + val android: ApplicationExtension = + this.extensions["android"] as ApplicationExtension + + android.namespace = + property(this, "POM_ARTIFACT_ID") + android.compileSdk = + propertyInt(this, "org.thepalaceproject.build.androidSDKCompile") + + android.defaultConfig { + multiDexEnabled = true + targetSdk = + propertyInt(this@allprojects, "org.thepalaceproject.build.androidSDKTarget") + minSdk = + propertyInt(this@allprojects, "org.thepalaceproject.build.androidSDKMinimum") + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + /* + * Produce JDK bytecode of the correct version. + */ + + tasks.withType { + kotlinOptions.jvmTarget = jdkBytecodeTarget.toString() + } + java.sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + java.targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + + android.compileOptions { + encoding = "UTF-8" + sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + } + } + + "aar" -> { + logger.info("Configuring ${this.project} $version as an aar project") + + apply(plugin = "com.android.library") + apply(plugin = "org.jetbrains.kotlin.android") + apply(plugin = "de.mannodermaus.android-junit5") + + /* + * Configure the JVM toolchain version that we want to use for Kotlin. + */ + + val kotlin: KotlinAndroidProjectExtension = + this.extensions["kotlin"] as KotlinAndroidProjectExtension + val java: JavaPluginExtension = + this.extensions["java"] as JavaPluginExtension + + kotlin.jvmToolchain(jdkBuild) + java.toolchain.languageVersion.set(JavaLanguageVersion.of(jdkBuild)) + + /* + * Configure the various required Android properties. + */ + + val android: LibraryExtension = + this.extensions["android"] as LibraryExtension + + android.namespace = + property(this, "POM_ARTIFACT_ID") + android.compileSdk = + propertyInt(this, "org.thepalaceproject.build.androidSDKCompile") + + android.defaultConfig { + multiDexEnabled = true + minSdk = + propertyInt(this@allprojects, "org.thepalaceproject.build.androidSDKMinimum") + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + /* + * Produce JDK bytecode of the correct version. + */ + + tasks.withType { + kotlinOptions.jvmTarget = jdkBytecodeTarget.toString() + } + java.sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + java.targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + + android.compileOptions { + encoding = "UTF-8" + sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + } + + android.testOptions { + execution = "ANDROIDX_TEST_ORCHESTRATOR" + animationsDisabled = true + + /* + * Enable the production of reports for all unit tests. + */ + + unitTests { + isIncludeAndroidResources = true + + all { test -> + // Required for the Mockito ByteBuddy agent on modern VMs. + test.systemProperty("jdk.attach.allowAttachSelf", "true") + test.reports.html.required = true + test.reports.junitXml.required = true + } + } + } + + /* + * Configure semantic versioning analysis. + */ + + afterEvaluate { + val enableSemanticVersionChecks = + propertyBoolean(this, "org.thepalaceproject.build.checkSemanticVersioning") + + if (enableSemanticVersionChecks) { + val verifyActual = createScandoAnalyzeTask(this) + verifyActual.dependsOn.add(scandoDownloadTask) + verifyActual.dependsOn.add("assembleDebug") + + val verifyTask = project.task("verifySemanticVersioning") + verifyTask.dependsOn.add(verifyActual) + } else { + // Create a do-nothing task to keep interface compatibility. + project.task("verifySemanticVersioning") + } + } + } + + "jar" -> { + logger.info("Configuring ${this.project} $version as a jar project") + + apply(plugin = "java-library") + apply(plugin = "org.jetbrains.kotlin.jvm") + + /* + * Configure the JVM toolchain versions that we want to use for Kotlin and Java. + */ + + val kotlin: KotlinProjectExtension = + this.extensions["kotlin"] as KotlinProjectExtension + val java: JavaPluginExtension = + this.extensions["java"] as JavaPluginExtension + + kotlin.jvmToolchain(jdkBuild) + java.toolchain.languageVersion.set(JavaLanguageVersion.of(jdkBuild)) + + /* + * Produce JDK bytecode of the correct version. + */ + + tasks.withType { + kotlinOptions.jvmTarget = jdkBytecodeTarget.toString() + } + java.sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + java.targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + + /* + * Configure JUnit tests. + */ + + tasks.named("test") { + useJUnitPlatform() + + // Required for the Mockito ByteBuddy agent on modern VMs. + systemProperty("jdk.attach.allowAttachSelf", "true") + + testLogging { + events("passed") + } + + this.reports.html.required = true + this.reports.junitXml.required = true + } + } + } + + /* + * Configure publishing. + */ + + when (extra["POM_PACKAGING"]) { + "jar", "aar" -> { + apply(plugin = "maven-publish") + + afterEvaluate { + configurePublishingFor(this.project) + } + } + } + + /* + * Configure some aggressive version resolution behaviour. The listed configurations have + * transitive dependency resolution enabled; all other configurations do not. This forces + * projects to be extremely explicit about what is imported. + */ + + val transitiveConfigurations = setOf( + "androidTestDebugImplementation", + "androidTestDebugImplementationDependenciesMetadata", + "androidTestImplementation", + "androidTestImplementationDependenciesMetadata", + "androidTestReleaseImplementation", + "androidTestReleaseImplementationDependenciesMetadata", + "annotationProcessor", + "debugAndroidTestCompilationImplementation", + "debugAndroidTestImplementation", + "debugAndroidTestImplementationDependenciesMetadata", + "debugAnnotationProcessor", + "debugAnnotationProcessorClasspath", + "debugUnitTestCompilationImplementation", + "debugUnitTestImplementation", + "debugUnitTestImplementationDependenciesMetadata", + "kotlinBuildToolsApiClasspath", + "kotlinCompilerClasspath", + "kotlinCompilerPluginClasspath", + "kotlinCompilerPluginClasspathDebug", + "kotlinCompilerPluginClasspathDebugAndroidTest", + "kotlinCompilerPluginClasspathDebugUnitTest", + "kotlinCompilerPluginClasspathMain", + "kotlinCompilerPluginClasspathRelease", + "kotlinCompilerPluginClasspathReleaseUnitTest", + "kotlinCompilerPluginClasspathTest", + "kotlinKlibCommonizerClasspath", + "kotlinNativeCompilerPluginClasspath", + "kotlinScriptDef", + "kotlinScriptDefExtensions", + "mainSourceElements", + "releaseAnnotationProcessor", + "releaseAnnotationProcessorClasspath", + "releaseUnitTestCompilationImplementation", + "releaseUnitTestImplementation", + "releaseUnitTestImplementationDependenciesMetadata", + "testDebugImplementation", + "testDebugImplementationDependenciesMetadata", + "testFixturesDebugImplementation", + "testFixturesDebugImplementationDependenciesMetadata", + "testFixturesImplementation", + "testFixturesImplementationDependenciesMetadata", + "testFixturesReleaseImplementation", + "testFixturesReleaseImplementationDependenciesMetadata", + "testImplementation", + "testImplementationDependenciesMetadata", + "testReleaseImplementation", + "testReleaseImplementationDependenciesMetadata", + ) + + /* + * Write the set of available configurations to files, for debugging purposes. Plugins can + * add new configurations at any time, and so it's nice to have a list of the available + * configurations visible. + */ + + val configurationsActual = mutableSetOf() + afterEvaluate { + configurations.all { + configurationsActual.add(this.name) + } + File("configurations.txt").writeText(configurationsActual.joinToString("\n")) + } + + afterEvaluate { + configurations.all { + isTransitive = transitiveConfigurations.contains(name) + // resolutionStrategy.failOnVersionConflict() + } + } + + /* + * Configure all "clean" tasks to depend upon the global Maven deployment directory cleaning + * task. + */ + + afterEvaluate { + tasks.matching { task -> task.name == "clean" } + .forEach { task -> task.dependsOn(cleanTask) } + } + + /* + * Configure all "test" tasks to be disabled. The tests are enabled only in those modules + * that specifically ask for them. Why do this? Because the Android plugins do lots of + * expensive per-module configuration for tests that don't exist. + */ + + afterEvaluate { + tasks.matching { task -> task.name.contains("UnitTest") } + .forEach { task -> task.enabled = false } + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..3b8ade7 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,27 @@ +GROUP=org.thepalaceproject.deploytest +POM_ARTIFACT_ID=org.thepalaceproject.deploytest +POM_DESCRIPTION=Deployment testing. +POM_INCEPTION_YEAR=2024 +POM_LICENCE_DIST=repo +POM_LICENCE_NAME=Apache 2.0 License +POM_LICENCE_URL=https://opensource.org/licenses/Apache-2.0 +POM_NAME=org.thepalaceproject.deploytest +POM_PACKAGING=pom +POM_SCM_CONNECTION=scm:git:git://github.com/ThePalaceProject/android-maven-central-testing +POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/ThePalaceProject/android-maven-central-testing +POM_SCM_URL=https://github.com/ThePalaceProject/android-maven-central-testing +POM_URL=https://github.com/ThePalaceProject/android-maven-central-testing +VERSION_NAME=1.0.0-SNAPSHOT +VERSION_PREVIOUS=1.0.0 + +android.useAndroidX=true +org.gradle.jvmargs=-Xmx4096m + +org.thepalaceproject.build.androidSDKCompile=34 +org.thepalaceproject.build.androidSDKTarget=34 +org.thepalaceproject.build.androidSDKMinimum=24 +org.thepalaceproject.build.checkSemanticVersioning=true +org.thepalaceproject.build.enableKtLint=true +org.thepalaceproject.build.jdkBytecodeTarget=11 +org.thepalaceproject.build.jdkBuild=17 +org.thepalaceproject.build.publishSources=true diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..fcb6fca --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..f47bf36 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,17 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + google() + } +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + google() + } +} + +rootProject.name = "org.thepalaceproject.deploytest" +