|
| 1 | +// SPDX-FileCopyrightText: 2021 Paul Schaub <info@pgpainless.org> |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +buildscript { |
| 6 | + |
| 7 | + repositories { |
| 8 | + |
| 9 | + maven { |
| 10 | + url "https://plugins.gradle.org/m2/" |
| 11 | + } |
| 12 | + mavenLocal() |
| 13 | + mavenCentral() |
| 14 | + } |
| 15 | + dependencies { |
| 16 | + classpath "gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0" |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +plugins { |
| 21 | + id 'ru.vyarus.animalsniffer' version '1.5.3' |
| 22 | +} |
| 23 | + |
| 24 | +apply from: 'version.gradle' |
| 25 | + |
| 26 | +allprojects { |
| 27 | + apply plugin: 'java' |
| 28 | + apply plugin: 'idea' |
| 29 | + apply plugin: 'eclipse' |
| 30 | + apply plugin: 'jacoco' |
| 31 | + apply plugin: 'checkstyle' |
| 32 | + |
| 33 | + // Only generate jar for submodules |
| 34 | + // without this we would generate an empty .jar for the project root |
| 35 | + // https://stackoverflow.com/a/25445035 |
| 36 | + jar { |
| 37 | + onlyIf { !sourceSets.main.allSource.files.isEmpty() } |
| 38 | + } |
| 39 | + |
| 40 | + // checkstyle |
| 41 | + checkstyle { |
| 42 | + toolVersion = '8.18' |
| 43 | + } |
| 44 | + |
| 45 | + group 'org.pgpainless' |
| 46 | + description = "Shared PGP Certificate Directory for Java" |
| 47 | + version = shortVersion |
| 48 | + |
| 49 | + sourceCompatibility = javaSourceCompatibility |
| 50 | + |
| 51 | + repositories { |
| 52 | + mavenCentral() |
| 53 | + } |
| 54 | + |
| 55 | + // Reproducible Builds |
| 56 | + tasks.withType(AbstractArchiveTask) { |
| 57 | + preserveFileTimestamps = false |
| 58 | + reproducibleFileOrder = true |
| 59 | + } |
| 60 | + |
| 61 | + project.ext { |
| 62 | + slf4jVersion = '1.7.32' |
| 63 | + logbackVersion = '1.2.9' |
| 64 | + junitVersion = '5.8.2' |
| 65 | + rootConfigDir = new File(rootDir, 'config') |
| 66 | + gitCommit = getGitCommit() |
| 67 | + isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI')) |
| 68 | + isReleaseVersion = !isSnapshot |
| 69 | + signingRequired = !(isSnapshot || isContinuousIntegrationEnvironment) |
| 70 | + sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword') |
| 71 | + sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots' |
| 72 | + sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' |
| 73 | + } |
| 74 | + |
| 75 | + if (isSnapshot) { |
| 76 | + version = version + '-SNAPSHOT' |
| 77 | + } |
| 78 | + def projectDirFile = new File("$projectDir") |
| 79 | + if (!project.ext.isSnapshot && !'git describe --exact-match HEAD'.execute(null, projectDirFile).text.trim().equals(ext.shortVersion)) { |
| 80 | + throw new InvalidUserDataException('Untagged version detected! Please tag every release.') |
| 81 | + } |
| 82 | + if (!version.endsWith('-SNAPSHOT') && version != 'git tag --points-at HEAD'.execute(null, projectDirFile).text.trim()) { |
| 83 | + throw new InvalidUserDataException( |
| 84 | + 'Tag mismatch detected, version is ' + version + ' but should be ' + |
| 85 | + 'git tag --points-at HEAD'.execute(null, projectDirFile).text.trim()) |
| 86 | + } |
| 87 | + |
| 88 | + jacoco { |
| 89 | + toolVersion = "0.8.7" |
| 90 | + } |
| 91 | + |
| 92 | + jacocoTestReport { |
| 93 | + dependsOn test |
| 94 | + sourceDirectories.setFrom(project.files(sourceSets.main.allSource.srcDirs)) |
| 95 | + classDirectories.setFrom(project.files(sourceSets.main.output)) |
| 96 | + reports { |
| 97 | + xml.enabled true |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + test { |
| 102 | + useJUnitPlatform() |
| 103 | + testLogging { |
| 104 | + events "passed", "skipped", "failed" |
| 105 | + exceptionFormat "full" |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +subprojects { |
| 111 | + apply plugin: 'maven-publish' |
| 112 | + apply plugin: 'signing' |
| 113 | + |
| 114 | + task sourcesJar(type: Jar, dependsOn: classes) { |
| 115 | + classifier = 'sources' |
| 116 | + from sourceSets.main.allSource |
| 117 | + } |
| 118 | + task javadocJar(type: Jar, dependsOn: javadoc) { |
| 119 | + classifier = 'javadoc' |
| 120 | + from javadoc.destinationDir |
| 121 | + } |
| 122 | + task testsJar(type: Jar, dependsOn: testClasses) { |
| 123 | + classifier = 'tests' |
| 124 | + from sourceSets.test.output |
| 125 | + } |
| 126 | + |
| 127 | + publishing { |
| 128 | + publications { |
| 129 | + mavenJava(MavenPublication) { |
| 130 | + from components.java |
| 131 | + artifact sourcesJar |
| 132 | + artifact javadocJar |
| 133 | + artifact testsJar |
| 134 | + pom { |
| 135 | + name = 'Cert-D-Java' |
| 136 | + description = 'Shared PGP Certificate Directory for Java' |
| 137 | + url = 'https://github.com/pgpainless/cert-d-java' |
| 138 | + inceptionYear = '2022' |
| 139 | + |
| 140 | + scm { |
| 141 | + url = 'https://github.com/pgpainless/cert-d-java' |
| 142 | + connection = 'scm:https://github.com/pgpainless/cert-d-java' |
| 143 | + developerConnection = 'scm:git://github.com/pgpainless/cert-d-java.git' |
| 144 | + } |
| 145 | + |
| 146 | + licenses { |
| 147 | + license { |
| 148 | + name = 'The Apache Software License, Version 2.0' |
| 149 | + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' |
| 150 | + distribution = 'repo' |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + developers { |
| 155 | + developer { |
| 156 | + id = 'vanitasvitae' |
| 157 | + name = 'Paul Schaub' |
| 158 | + email = 'vanitasvitae@fsfe.org' |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + repositories { |
| 165 | + if (sonatypeCredentialsAvailable) { |
| 166 | + maven { |
| 167 | + url isSnapshot ? sonatypeSnapshotUrl : sonatypeStagingUrl |
| 168 | + credentials { |
| 169 | + username = sonatypeUsername |
| 170 | + password = sonatypePassword |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + signing { |
| 178 | + useGpgCmd() |
| 179 | + required { signingRequired } |
| 180 | + sign publishing.publications.mavenJava |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +def getGitCommit() { |
| 185 | + def projectDirFile = new File("$projectDir") |
| 186 | + def dotGit = new File("$projectDir/.git") |
| 187 | + if (!dotGit.isDirectory()) return 'non-git build' |
| 188 | + |
| 189 | + def cmd = 'git describe --always --tags --dirty=+' |
| 190 | + def proc = cmd.execute(null, projectDirFile) |
| 191 | + def gitCommit = proc.text.trim() |
| 192 | + assert !gitCommit.isEmpty() |
| 193 | + |
| 194 | + def srCmd = 'git symbolic-ref --short HEAD' |
| 195 | + def srProc = srCmd.execute(null, projectDirFile) |
| 196 | + srProc.waitForOrKill(10 * 1000) |
| 197 | + if (srProc.exitValue() == 0) { |
| 198 | + // Only add the information if the git command was |
| 199 | + // successful. There may be no symbolic reference for HEAD if |
| 200 | + // e.g. in detached mode. |
| 201 | + def symbolicReference = srProc.text.trim() |
| 202 | + assert !symbolicReference.isEmpty() |
| 203 | + gitCommit += "-$symbolicReference" |
| 204 | + } |
| 205 | + |
| 206 | + gitCommit |
| 207 | +} |
| 208 | + |
| 209 | +apply plugin: "com.github.kt3k.coveralls" |
| 210 | +coveralls { |
| 211 | + sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath |
| 212 | +} |
| 213 | + |
| 214 | +task jacocoRootReport(type: JacocoReport) { |
| 215 | + dependsOn = subprojects.jacocoTestReport |
| 216 | + sourceDirectories.setFrom(files(subprojects.sourceSets.main.allSource.srcDirs)) |
| 217 | + classDirectories.setFrom(files(subprojects.sourceSets.main.output)) |
| 218 | + executionData.setFrom(files(subprojects.jacocoTestReport.executionData)) |
| 219 | + reports { |
| 220 | + xml.enabled true |
| 221 | + xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml") |
| 222 | + } |
| 223 | + // We could remove the following setOnlyIf line, but then |
| 224 | + // jacocoRootReport would silently be SKIPPED if something with |
| 225 | + // the projectsWithUnitTests is wrong (e.g. a project is missing |
| 226 | + // in there). |
| 227 | + setOnlyIf { true } |
| 228 | +} |
| 229 | + |
| 230 | +task javadocAll(type: Javadoc) { |
| 231 | + def currentJavaVersion = JavaVersion.current() |
| 232 | + if (currentJavaVersion.compareTo(JavaVersion.VERSION_1_9) >= 0) { |
| 233 | + options.addStringOption("-release", "8"); |
| 234 | + } |
| 235 | + source subprojects.collect {project -> |
| 236 | + project.sourceSets.main.allJava } |
| 237 | + destinationDir = new File(buildDir, 'javadoc') |
| 238 | + // Might need a classpath |
| 239 | + classpath = files(subprojects.collect {project -> |
| 240 | + project.sourceSets.main.compileClasspath}) |
| 241 | + options.linkSource = true |
| 242 | + options.use = true |
| 243 | + options.links = [ |
| 244 | + "https://docs.oracle.com/javase/${sourceCompatibility.getMajorVersion()}/docs/api/", |
| 245 | + ] as String[] |
| 246 | +} |
0 commit comments