|
| 1 | +buildscript { |
| 2 | + // Typically, only edit those two: |
| 3 | + val objectboxVersionNumber = "3.3.2" // without "-SNAPSHOT", e.g. "2.5.0" or "2.4.0-RC" |
| 4 | + val objectboxVersionRelease = |
| 5 | + false // set to true for releasing to ignore versionPostFix to avoid e.g. "-dev" versions |
| 6 | + |
| 7 | + // version post fix: "-<value>" or "" if not defined; e.g. used by CI to pass in branch name |
| 8 | + val versionPostFixValue = project.findProperty("versionPostFix") |
| 9 | + val versionPostFix = if (versionPostFixValue != null) "-$versionPostFixValue" else "" |
| 10 | + val obxJavaVersion by extra(objectboxVersionNumber + (if (objectboxVersionRelease) "" else "$versionPostFix-SNAPSHOT")) |
| 11 | + |
| 12 | + // Native library version for tests |
| 13 | + // Be careful to diverge here; easy to forget and hard to find JNI problems |
| 14 | + val nativeVersion = objectboxVersionNumber + (if (objectboxVersionRelease) "" else "-dev-SNAPSHOT") |
| 15 | + val osName = System.getProperty("os.name").toLowerCase() |
| 16 | + val objectboxPlatform = when { |
| 17 | + osName.contains("linux") -> "linux" |
| 18 | + osName.contains("windows") -> "windows" |
| 19 | + osName.contains("mac") -> "macos" |
| 20 | + else -> "unsupported" |
| 21 | + } |
| 22 | + val obxJniLibVersion by extra("io.objectbox:objectbox-$objectboxPlatform:$nativeVersion") |
| 23 | + |
| 24 | + val essentialsVersion by extra("3.1.0") |
| 25 | + val juniVersion by extra("4.13.2") |
| 26 | + val mockitoVersion by extra("3.8.0") |
| 27 | + val kotlinVersion by extra("1.7.0") |
| 28 | + val coroutinesVersion by extra("1.6.2") |
| 29 | + val dokkaVersion by extra("1.6.10") |
| 30 | + |
| 31 | + println("version=$obxJavaVersion") |
| 32 | + println("objectboxNativeDependency=$obxJniLibVersion") |
| 33 | + |
| 34 | + repositories { |
| 35 | + mavenCentral() |
| 36 | + maven { |
| 37 | + url = uri("https://plugins.gradle.org/m2/") |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + dependencies { |
| 42 | + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") |
| 43 | + classpath("org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion") |
| 44 | + // https://github.com/spotbugs/spotbugs-gradle-plugin/releases |
| 45 | + classpath("gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.0") |
| 46 | + classpath("io.github.gradle-nexus:publish-plugin:1.1.0") |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +allprojects { |
| 51 | + group = "io.objectbox" |
| 52 | + val obxJavaVersion: String by rootProject.extra |
| 53 | + version = obxJavaVersion |
| 54 | + |
| 55 | + repositories { |
| 56 | + mavenCentral() |
| 57 | + } |
| 58 | + |
| 59 | + configurations.all { |
| 60 | + // Projects are using snapshot dependencies that may update more often than 24 hours. |
| 61 | + resolutionStrategy { |
| 62 | + cacheChangingModulesFor(0, "seconds") |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +// Make javadoc task errors not break the build, some are in third-party code. |
| 68 | +if (JavaVersion.current().isJava8Compatible) { |
| 69 | + allprojects { |
| 70 | + tasks.withType<Javadoc> { |
| 71 | + isFailOnError = false |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +val projectNamesToPublish = listOf( |
| 77 | + "objectbox-java-api", |
| 78 | + "objectbox-java", |
| 79 | + "objectbox-kotlin", |
| 80 | + "objectbox-rxjava", |
| 81 | + "objectbox-rxjava3" |
| 82 | +) |
| 83 | + |
| 84 | +fun hasSigningProperties(): Boolean { |
| 85 | + return (project.hasProperty("signingKeyId") |
| 86 | + && project.hasProperty("signingKeyFile") |
| 87 | + && project.hasProperty("signingPassword")) |
| 88 | +} |
| 89 | + |
| 90 | +configure(subprojects.filter { projectNamesToPublish.contains(it.name) }) { |
| 91 | + apply(plugin = "maven-publish") |
| 92 | + apply(plugin = "signing") |
| 93 | + |
| 94 | + configure<PublishingExtension> { |
| 95 | + repositories { |
| 96 | + maven { |
| 97 | + name = "GitLab" |
| 98 | + if (project.hasProperty("gitlabUrl") && project.hasProperty("gitlabPrivateToken")) { |
| 99 | + // "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven" |
| 100 | + val gitlabUrl = project.property("gitlabUrl") |
| 101 | + url = uri("$gitlabUrl/api/v4/projects/14/packages/maven") |
| 102 | + println("GitLab repository set to $url.") |
| 103 | + |
| 104 | + credentials(HttpHeaderCredentials::class) { |
| 105 | + name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token" |
| 106 | + value = project.property("gitlabPrivateToken").toString() |
| 107 | + } |
| 108 | + authentication { |
| 109 | + create<HttpHeaderAuthentication>("header") |
| 110 | + } |
| 111 | + } else { |
| 112 | + println("WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set.") |
| 113 | + } |
| 114 | + } |
| 115 | + // Note: Sonatype repo created by publish-plugin. |
| 116 | + } |
| 117 | + |
| 118 | + publications { |
| 119 | + create<MavenPublication>("mavenJava") { |
| 120 | + // Note: Projects set additional specific properties. |
| 121 | + pom { |
| 122 | + packaging = "jar" |
| 123 | + url.set("https://objectbox.io") |
| 124 | + licenses { |
| 125 | + license { |
| 126 | + name.set("The Apache Software License, Version 2.0") |
| 127 | + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") |
| 128 | + distribution.set("repo") |
| 129 | + } |
| 130 | + } |
| 131 | + developers { |
| 132 | + developer { |
| 133 | + id.set("ObjectBox") |
| 134 | + name.set("ObjectBox") |
| 135 | + } |
| 136 | + } |
| 137 | + issueManagement { |
| 138 | + system.set("GitHub Issues") |
| 139 | + url.set("https://github.com/objectbox/objectbox-java/issues") |
| 140 | + } |
| 141 | + organization { |
| 142 | + name.set("ObjectBox Ltd.") |
| 143 | + url.set("https://objectbox.io") |
| 144 | + } |
| 145 | + scm { |
| 146 | + connection.set("scm:git@github.com:objectbox/objectbox-java.git") |
| 147 | + developerConnection.set("scm:git@github.com:objectbox/objectbox-java.git") |
| 148 | + url.set("https://github.com/objectbox/objectbox-java") |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + configure<SigningExtension> { |
| 156 | + if (hasSigningProperties()) { |
| 157 | + val signingKey = File(project.property("signingKeyFile").toString()).readText() |
| 158 | + useInMemoryPgpKeys( |
| 159 | + project.property("signingKeyId").toString(), |
| 160 | + signingKey, |
| 161 | + project.property("signingPassword").toString() |
| 162 | + ) |
| 163 | + sign((extensions.getByName("publishing") as PublishingExtension).publications["mavenJava"]) |
| 164 | + } else { |
| 165 | + println("Signing information missing/incomplete for ${project.name}") |
| 166 | + } |
| 167 | + } |
| 168 | +} |
| 169 | + |
| 170 | +tasks.wrapper { |
| 171 | + distributionType = Wrapper.DistributionType.ALL |
| 172 | +} |
| 173 | + |
| 174 | +// Plugin to publish to Central https://github.com/gradle-nexus/publish-plugin/ |
| 175 | +// This plugin ensures a separate, named staging repo is created for each build when publishing. |
| 176 | +apply(plugin = "io.github.gradle-nexus.publish-plugin") |
| 177 | +configure<io.github.gradlenexus.publishplugin.NexusPublishExtension> { |
| 178 | + repositories { |
| 179 | + sonatype { |
| 180 | + if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) { |
| 181 | + println("nexusPublishing credentials supplied.") |
| 182 | + username.set(project.property("sonatypeUsername").toString()) |
| 183 | + password.set(project.property("sonatypePassword").toString()) |
| 184 | + } else { |
| 185 | + println("nexusPublishing credentials NOT supplied.") |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + transitionCheckOptions { // Maven Central may become very, very slow in extreme situations |
| 190 | + maxRetries.set(900) // with default delay of 10s, that's 150 minutes total; default is 60 (10 minutes) |
| 191 | + } |
| 192 | +} |
0 commit comments