plugins { id 'java' id 'application' id 'maven' id 'signing' } repositories { mavenCentral() flatDir { // SWT libraries dirs "./swt-lib" } } mainClassName = 'com.webcodepro.applecommander.ui.AppleCommander' version "${version}" compileJava { sourceCompatibility = '1.8' targetCompatibility = '1.8' } test { String osName = System.getProperty('os.name').toLowerCase().split()[0] String osArch = System.getProperty('os.arch').toLowerCase().split()[0] String swtDependency switch (osName) { case 'windows': swtDependency = "org.eclipse.swt:org.eclipse.swt.win32.win32.x86_64:$swtVersion" break case 'linux': swtDependency = "org.eclipse.swt:org.eclipse.swt.gtk.linux.x86_64:$swtVersion" if (osArch == 'arm') { swtDependency = "org.eclipse.swt:org.eclipse.swt.gtk.linux.arm:$piswtVersion" } break case 'mac': swtDependency = "org.eclipse.swt:org.eclipse.swt.cocoa.macosx.x86_64:$swtVersion" break default: throw new Exception('Unknown OS') } dependencies { implementation "$swtDependency" } testLogging { exceptionFormat = 'full' } } // Disable default JAR creation project.tasks.jar.setEnabled(false) // Generic additions to JAR creation tasks.withType(Jar) { manifest { attributes 'Main-Class': 'com.webcodepro.applecommander.ui.AppleCommander' attributes 'Implementation-Title': 'AppleCommander', 'Implementation-Version': archiveVersion } from('LICENSE') doFirst { // Jar files with an appendix are standalone applications and need to have ShrinkIt included. if (archiveAppendix) { from { configurations.runtimeClasspath.collect { it.name.startsWith('ShrinkItArchive') || it.name.startsWith('applesingle-api') || it.name.startsWith('bastools-api') || it.name.startsWith('commons-csv') || it.name.startsWith('gson') ? zipTree(it) : 'fake' } } } } } dependencies { implementation "net.sf.applecommander:ShrinkItArchive:$shkVersion" implementation "net.sf.applecommander:applesingle-api:$asVersion" implementation "net.sf.applecommander:bastools-api:$btVersion" implementation "org.apache.commons:commons-csv:$commonsCsvVersion" implementation "com.google.code.gson:gson:$gsonVersion" compileOnly "org.apache.ant:ant:$antVersion" testImplementation "junit:junit:$junitVersion" testImplementation "org.apache.commons:commons-lang3:$commonsLang3Version" } task mavenJar(type: Jar) { dependencies { // Just to pass the compile step; these classes are stripped out below. implementation "org.eclipse.swt:org.eclipse.swt.cocoa.macosx.x86_64:$swtVersion" } from(sourceSets.main.output) { include 'com/webcodepro/applecommander/**' exclude 'com/webcodepro/applecommander/ui/images/**' exclude 'com/webcodepro/applecommander/ui/swing/**' exclude 'com/webcodepro/applecommander/ui/swt/**' } } task acJar(type: Jar) { dependencies { // Just to pass the compile step; these classes are stripped out below. implementation "org.eclipse.swt:org.eclipse.swt.cocoa.macosx.x86_64:$swtVersion" } archiveAppendix = 'ac' manifest { attributes 'Main-Class' : 'com.webcodepro.applecommander.ui.ac' } from(sourceSets.main.output) { include 'com/webcodepro/**' exclude 'com/webcodepro/applecommander/ui/images/**' exclude 'com/webcodepro/applecommander/ui/swing/**' exclude 'com/webcodepro/applecommander/ui/swt/**' } } task linuxJar(type: Jar) { dependencies { implementation "org.eclipse.swt:org.eclipse.swt.gtk.linux.x86_64:$swtVersion" } archiveAppendix = 'linux64-gtk' from(sourceSets.main.output) { include 'com/webcodepro/**' } doFirst { // Pick and include just the Linux JAR contents from { configurations.runtimeClasspath.collect { it.name.contains('.linux.x86_64-') ? zipTree(it) : 'fake' } } } } task piJar(type: Jar) { dependencies { implementation "org.eclipse.swt:org.eclipse.swt.gtk.linux.arm:$piswtVersion" } archiveAppendix = 'linuxarm-gtk' from(sourceSets.main.output) { include 'com/webcodepro/**' } doFirst { // Pick and include just the Linux JAR contents from { configurations.runtimeClasspath.collect { it.name.contains('.linux.arm-') ? zipTree(it) : 'fake' } } } } task macosxJar(type: Jar) { dependencies { implementation "org.eclipse.swt:org.eclipse.swt.cocoa.macosx.x86_64:$swtVersion" } archiveAppendix = 'macosx' from(sourceSets.main.output) { include 'com/webcodepro/**' } doFirst { // Pick and include just the Mac OS X JAR contents from { configurations.runtimeClasspath.collect { it.name.contains('.macosx.') ? zipTree(it) : 'fake' } } } } task windowsJar(type: Jar) { dependencies { implementation "org.eclipse.swt:org.eclipse.swt.win32.win32.x86_64:$swtVersion" } archiveAppendix = 'win64' from(sourceSets.main.output) { include 'com/webcodepro/**' } doFirst { // Pick and include just the Windows SWT JAR contents from { configurations.runtimeClasspath.collect { it.name.contains('.win32.') ? zipTree(it) : 'fake' } } } } task javadocJar(type: Jar) { classifier = 'javadoc' from javadoc } task sourcesJar(type: Jar) { classifier = 'sources' from sourceSets.main.allSource } javadoc { options.addStringOption('Xdoclint:none', '-quiet') } artifacts { archives mavenJar, acJar archives linuxJar, piJar, macosxJar, windowsJar archives javadocJar, sourcesJar } signing { // Only sign if we're uploading... required { gradle.taskGraph.hasTask("uploadArchives") } sign configurations.archives } uploadArchives { repositories { mavenDeployer { addFilter('AppleCommander') { artifact, file -> // Note that the other executables all have suffixes which change their name. return artifact.name == 'AppleCommander' && artifact.ext != 'zip' && artifact.ext != 'tar' } beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword')) } snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword')) } // Only preserve the compile and non-SWT POM dependencies pom('AppleCommander').whenConfigured { p -> p.dependencies = p.dependencies.findAll { it.scope == "compile" } p.dependencies = p.dependencies.findAll { it.groupId != "org.eclipse.swt" } } pom('AppleCommander').project { name archivesBaseName packaging 'jar' description 'AppleCommander is a general utility for Apple II disk images.' url 'https://applecommander.github.io/' scm { url 'https://github.com/AppleCommander/AppleCommander' } licenses { license { name 'The GNU General Public License (GPL) Version 2, June 1991' url 'https://www.gnu.org/licenses/gpl-2.0.html' } } developers { developer { id 'robgreene' email 'robgreene@gmail.com' } } } } } }