Java-Installer/build.gradle

172 lines
5.0 KiB
Groovy

plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'maven-publish'
id 'signing'
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}
// Set version of programm //
version = project.file("./VERSION").text.trim()
def version = project.file("./VERSION").text.trim()
def publishToNexus = "publishToSonatype" in gradle.startParameter.taskNames
group = "de.rpjosh"
// ----- //
// Set correct encoding
compileJava.options.encoding = 'UTF-8'
tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
}
sourceCompatibility = 11
targetCompatibility = 11
// Create a single .jar with all dependencies
task fatJar(type: Jar) {
archiveClassifier = ''
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes( 'Implementation-Title': 'installer',
'Implementation-Version': version,
'Implementation-Group': project.group, )
}
archivesBaseName = "installer"
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
{
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
with jar
destinationDirectory.set(layout.buildDirectory.dir("dist"))
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
//sourceSets.main.resources { srcDirs = ["src/main/java"]; exclude "**/*.java" }
task javadocJar(type: Jar, dependsOn: javadoc) {
manifest {
attributes( 'Implementation-Title': 'installer',
'Implementation-Version': version,
'Implementation-Group': project.group, )
}
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives fatJar
archives sourcesJar
archives javadocJar
}
// The created jar file will be copied automatically into the release directory
task copyJar(type: Copy) {
from file("$buildDir/dist/installer-" + version + ".jar"), file("$buildDir/libs/installer-" + version + "-javadoc.jar"), file("$buildDir/libs/installer-" + version + "-sources.jar")
into file("$buildDir/../release")
}
// Build the maven repo file structure -> Javadoc can be used easily in eclipse
task copyJarToMaven (type: Copy) {
from file("$buildDir/dist/installer-" + version + ".jar"), file("$buildDir/libs/installer-" + version + "-javadoc.jar"), file("$buildDir/libs/installer-" + version + "-sources.jar")
into file("$buildDir/../release/mavenRepo/de/rpjosh/installer/" + version)
}
// Publish to local maven repo
java {
withJavadocJar()
withSourcesJar()
}
nexusPublishing {
repositories {
sonatype{
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
// Or use System.getenv?
username= publishToNexus ? project.property("maven.sonatype.user") : "none"
password= publishToNexus ? project.property("maven.sonatype.password") : "none"
}
}
}
publishing {
publications {
javaPubl(MavenPublication) {
artifactId = 'installer'
from components.java
pom {
name = 'Java-Installer'
description = 'A simple installation routine for your Java application'
url = 'https://git.rpjosh.de/RPJosh/Java-Installer'
licenses {
license {
name = 'The GNU AFFERO GENERAL PUBLIC LICENSE, Version 3'
url = 'https://www.gnu.org/licenses/agpl-3.0.html'
}
}
developers {
developer {
id = 'RPJosh'
name = 'Jonas Letzbor'
email = 'RPjosh@rpjosh.de'
}
}
scm {
connection = 'scm:git:https://git.rpjosh.de/RPJosh/Java-Installer.git'
developerConnection = 'scm:git:https://git.rpjosh.de/RPJosh/Java-Installer.git'
url = 'https://git.rpjosh.de/RPJosh/Java-Installer'
}
}
}
}
}
signing {
def signingKey = publishToNexus ? project.property("maven.sonatype.signing.key") : ""
def signingPassword = publishToNexus ? project.property("maven.sonatype.signing.password") : ""
useInMemoryPgpKeys(signingKey, signingPassword)
// Only sign the publications
sign publishing.publications.javaPubl
}
build.finalizedBy copyJar
build.finalizedBy copyJarToMaven
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/com.github.vatbub/mslinks
api group: 'com.github.vatbub', name: 'mslinks', version: '1.0.6.2'
}
tasks.named('jar') {
manifest {
attributes( 'Implementation-Title': 'installer',
'Implementation-Version': version,
'Implementation-Group': 'de.rpjosh', )
}
}