import java.text.SimpleDateFormat buildscript { dependencies { // Create OSGI bundles classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:4.3.1" } } plugins { id 'java' id 'eclipse' id 'idea' id 'maven' id 'signing' } apply plugin: 'biz.aQute.bnd.builder' // https://reproducible-builds.org/docs/source-date-epoch/ String source_date_epoch = System.getenv("SOURCE_DATE_EPOCH"); if (source_date_epoch != null) { TimeZone.setDefault(TimeZone.getTimeZone("UTC")) } Date buildTimeAndDate = source_date_epoch == null ? new Date() : new Date(1000 * Long.parseLong(source_date_epoch)) ext { buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate) buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate) builtByValue = project.hasProperty('builtBy') ? project.builtBy : project.defaultBuiltBy } description = '@API Guardian' def moduleName = 'org.apiguardian.api' repositories { mavenCentral() } compileJava { options.compilerArgs = ['--release', '8'] } task compileModule(type: JavaCompile) { def moduleSrcDir = file('src/module/java') source(moduleSrcDir) destinationDir = file("$buildDir/classes/java/modules") classpath = compileJava.classpath inputs.property("moduleName", moduleName) inputs.property("moduleVersion", project.version) options.compilerArgs = [ '--release', '9', '--module-version', project.version as String, '--module-source-path', moduleSrcDir.toString(), '--patch-module', "$moduleName=${sourceSets.main.allJava.srcDirs.join(':')}", '--module', moduleName ] } def normalizeVersion = { versionLiteral -> try { (versionLiteral =~ /(\d+)\.(\d+)\.(\d+).*/)[0][1..3].join('.') } catch (e) { throw new GradleException("Version '$versionLiteral' does not match version pattern, e.g. 1.0.0-QUALIFIER", e) } } jar { manifest { attributes( 'Created-By': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})".toString(), 'Built-By': builtByValue, 'Build-Date': buildDate, 'Build-Time': buildTime, 'Specification-Title': project.name, 'Specification-Version': normalizeVersion(project.version), 'Specification-Vendor': 'apiguardian.org', 'Implementation-Title': project.name, 'Implementation-Version': project.version, 'Implementation-Vendor': 'apiguardian.org', 'Bundle-Name': project.name, 'Bundle-Description': project.description, 'Bundle-DocURL': 'https://github.com/apiguardian-team/apiguardian', 'Bundle-Vendor': 'apiguardian.org', '-exportcontents': 'org.apiguardian.api', 'Bundle-SymbolicName': moduleName ) } from(files("${compileModule.destinationDir}/$moduleName").builtBy(compileModule)) { include('module-info.class') } } javadoc { options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED options.author = true options.header = '@API Guardian' options.addStringOption('Xdoclint:html,syntax,reference', '-quiet') options.links 'https://docs.oracle.com/en/java/javase/11/docs/api/' } task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource } task javadocJar(type: Jar) { classifier = 'javadoc' from javadoc } artifacts { archives sourcesJar archives javadocJar } def signArtifacts = !project.version.contains('SNAPSHOT') if (signArtifacts) { signing { sign configurations.archives } } uploadArchives { dependsOn check repositories { mavenDeployer { if (signArtifacts) { beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } } def ossrhUsername = rootProject.hasProperty('ossrhUsername') ? rootProject.ossrhUsername : '' def ossrhPassword = rootProject.hasProperty('ossrhPassword') ? rootProject.ossrhPassword : '' repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { authentication(userName: ossrhUsername, password: ossrhPassword) } snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { authentication(userName: ossrhUsername, password: ossrhPassword) } pom.project { name "${project.group}:${project.name}" packaging 'jar' description "@API Guardian" url 'https://github.com/apiguardian-team/apiguardian' scm { connection 'scm:git:git://github.com/apiguardian-team/apiguardian.git' developerConnection 'scm:git:git://github.com/apiguardian-team/apiguardian.git' url 'https://github.com/apiguardian-team/apiguardian' } licenses { license { name 'The Apache License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id 'apiguardian' name '@API Guardian Team' email 'team@apiguardian.org' } } } pom.whenConfigured { p -> p.dependencies = p.dependencies.findAll { dep -> dep.scope != 'test' } } } } } def docsVersion = project.version.contains('SNAPSHOT') ? 'snapshot' : project.version def docsDir = new File(buildDir, 'ghpages-docs') task prepareDocsForUploadToGhPages(dependsOn: [javadoc], type: Copy) { outputs.dir docsDir from("$buildDir/docs") { include 'javadoc/**' } into "${docsDir}/${docsVersion}" filesMatching('javadoc/**') { fileCopyDetails -> fileCopyDetails.path = fileCopyDetails.path.replace('javadoc/', 'api/') } includeEmptyDirs = false } task createCurrentDocsFolder(dependsOn: prepareDocsForUploadToGhPages, type: Copy) { outputs.dir "${docsDir}/current" from "${docsDir}/${docsVersion}" into "${docsDir}/current" } createCurrentDocsFolder.onlyIf { project.hasProperty('replaceCurrentDocs') }