Skip to content
Snippets Groups Projects
build.gradle 3.98 KiB
Newer Older
import java.text.SimpleDateFormat

plugins {
    id 'java'
    id 'idea'
}

group 'de.griefed'

//noinspection GroovyUnusedAssignment
sourceCompatibility = targetCompatibility = '1.8'

sourceSets {
    //noinspection GroovyAssignabilityCheck
    main {
        java {
            srcDirs = ['src/main/java']
        }
        //noinspection GroovyAssignabilityCheck
        resources {
            srcDirs = ['src/main/resources']
        }
    }
    test {
        java {
            srcDirs = ['src/test/java']
        }
        //noinspection GroovyAssignabilityCheck
        resources {
            srcDirs = ['src/test/resources']
        }
    }
}

repositories {
    mavenCentral()
}

configurations {
    embed
    implementation.extendsFrom(embed)
}

dependencies {
    embed 'com.typesafe:config:1.4.1'

    // Testing
    testImplementation 'org.mockito:mockito-core:4.1.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
    useJUnitPlatform()
    // Mention test result in logs
    testLogging {
        events "passed",
                "skipped",
                "failed"
    }
}

// Include specific files in resources folder, like the license and readme.
tasks.register('about', Copy) {
    dependsOn tasks.named('clean')

    from layout.projectDirectory.file("LICENSE") into layout.projectDirectory.dir("src/main/resources")
    from layout.projectDirectory.file("README.md") into layout.projectDirectory.dir("src/main/resources")
}

tasks.withType(Javadoc) {
    options.addStringOption('encoding', 'UTF-8')
}

javadoc {
    options.memberLevel = JavadocMemberLevel.PRIVATE
    classpath = sourceSets.main.runtimeClasspath
}

java {
    withSourcesJar()
    withJavadocJar()
}

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE

    from {
        configurations.embed.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
    }

    //noinspection GroovyAssignabilityCheck
    manifest {
        attributes(
                "Main-Class"     : "de.griefed.serverpackcreatoraddonexample.Main",
                "Class-Path"     : configurations.embed.findAll { it.name.endsWith('jar') }.collect { zipTree(it) },
                "Description"    : "Example addon for ServerPackCreator",
                "Built-By"       : System.getProperty("user.name"),
                "Build-Timestamp": new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
                "Created-By"     : "Gradle ${gradle.gradleVersion}",
                "Build-Jdk"      : "${System.getProperty('java.version')} (${System.getProperty('java.vendor')} ${System.getProperty('java.vm.version')})",
                "Build-OS"       : "${System.getProperty('os.name')} ${System.getProperty('os.arch')} ${System.getProperty('os.version')}",
        )
    }
    exclude (
            'META-INF/org',
            'META-INF/org/**',
            'META-INF/versions',
            'META-INF/versions/**',
            'META-INF/DEPENDENCIES',
            'META-INF/LICENSE',
            'META-INF/NOTICE',
            'META-INF/CHANGES',
            'META-INF/LICENSE.txt',
            'META-INF/NOTICE.txt',
            'META-INF/README.md',
            'Log4j-**'
    )
}

// Publish the package with passed version to GHPR. Use ./gradlew -Pversion=${NEW_VERSION} publish, for example.
publishing {
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/Griefed/serverpackcreatorexampleaddon")
            credentials {
                username = System.getenv("GITHUB_ACTOR")
                password = System.getenv("GITHUB_TOKEN")
            }
        }
    }
    publications {
        //noinspection GroovyAssignabilityCheck
        gpr(MavenPublication) {
            //noinspection GroovyAssignabilityCheck
            artifactId='serverpackcreatorexampleaddon'
            //noinspection GroovyAssignabilityCheck
            from (components.java)
        }
    }