Skip to content
Snippets Groups Projects
build.gradle 4 KiB
Newer Older
  • Learn to ignore specific revisions
  • Georg Seibt's avatar
    Georg Seibt committed
    plugins {
    
    Georg Seibt's avatar
    Georg Seibt committed
        id 'java-library'
        id 'maven-publish'
    
    
    Georg Seibt's avatar
    Georg Seibt committed
        id 'idea'
    
    Georg Seibt's avatar
    Georg Seibt committed
    
    
    Georg Seibt's avatar
    Georg Seibt committed
        id "com.github.hierynomus.license" version "0.16.1" // Used to ensure that licence headers are applied consistently
    
    Georg Seibt's avatar
    Georg Seibt committed
        id "com.github.ben-manes.versions" version "0.42.0" // Used to check for new plugin / dependency versions.
    
    Georg Seibt's avatar
    Georg Seibt committed
    }
    
    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }
    
    
    Georg Seibt's avatar
    Georg Seibt committed
    javadoc {
        options.setEncoding 'UTF-8'
    
        if(JavaVersion.current().isJava9Compatible()) {
            options.addBooleanOption('html5', true)
        }
    }
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'commons-io:commons-io:2.11.0'
    }
    
    
    Georg Seibt's avatar
    Georg Seibt committed
    sourceSets {
        main {
            java {
                srcDir 'src'
            }
        }
    }
    
    
    java {
        toolchain {
            languageVersion = JavaLanguageVersion.of(11)
        }
    }
    
    
    Georg Seibt's avatar
    Georg Seibt committed
    idea {
        module {
            downloadJavadoc = true
            downloadSources = true
        }
    
    }
    
    compileJava {
        options.compilerArgs << "-Xlint:all"
    
    Georg Seibt's avatar
    Georg Seibt committed
    }
    
    group "de.uni_passau.fim.seibt"
    
    if (System.getenv("GITLAB_CI") != null) {
        task sourcesJar(type: Jar) {
            from sourceSets.main.allJava
            archiveClassifier = 'sources'
        }
    
        task javadocJar(type: Jar) {
            from javadoc
            archiveClassifier = 'javadoc'
        }
    
        final CI_COMMIT_TAG = System.getenv('CI_COMMIT_TAG')
        final CI_JOB_MANUAL = System.getenv('CI_JOB_MANUAL') != null
    
        if (!CI_JOB_MANUAL && CI_COMMIT_TAG != null) {
    
    Georg Seibt's avatar
    Georg Seibt committed
            // Match tags like '2022.1'
    
    Georg Seibt's avatar
    Georg Seibt committed
            // If we are not building a manual snapshot the short SHA of the commit being built is used.
    
    Georg Seibt's avatar
    Georg Seibt committed
            final VERSION_MATCHER = (CI_COMMIT_TAG =~ /[1-9]\d{3,}\.(?:0|[1-9]\d*)/)
    
    Georg Seibt's avatar
    Georg Seibt committed
            if (VERSION_MATCHER.matches()) {
                project.version = CI_COMMIT_TAG
    
    Georg Seibt's avatar
    Georg Seibt committed
            } else {
                throw new GradleScriptException('Invalid version tag \'' + CI_COMMIT_TAG + '\'')
            }
        } else {
            project.version = System.getenv('CI_COMMIT_SHORT_SHA')
        }
    
        publishing {
    
            publications {
    
    Georg Seibt's avatar
    Georg Seibt committed
                GitWrapper(MavenPublication) {
    
    Georg Seibt's avatar
    Georg Seibt committed
                    final BASE_ID = 'gitwrapper'
    
                    if (CI_JOB_MANUAL) {
                        artifactId = BASE_ID + '-snapshot'
                    } else {
                        artifactId = BASE_ID
                    }
    
                    from components.java
                    artifact sourcesJar
                    artifact javadocJar
    
                    pom {
                        name = 'GitWrapper'
                        description = 'A Java library wrapping system calls to a natively installed git executable.'
                        url = 'https://gitlab.infosun.fim.uni-passau.de/seibt/GitWrapper'
                        licenses {
                            license {
                                name = 'GNU Lesser General Public License V3'
                                url = 'https://www.gnu.org/licenses/lgpl-3.0.de.html'
                            }
                        }
                        developers {
                            developer {
                                id = 'seibt'
                                name = 'Georg Seibt'
                                email = 'seibt@fim.uni-passau.de'
                            }
                        }
                        scm {
                            connection = 'scm:git:https://gitlab.infosun.fim.uni-passau.de/seibt/GitWrapper.git'
                            developerConnection = 'scm:git:ssh://git@gitlab.infosun.fim.uni-passau.de:seibt/GitWrapper.git'
                            url = 'https://gitlab.infosun.fim.uni-passau.de/seibt/GitWrapper'
                        }
                    }
                }
            }
    
            repositories {
                maven {
                    name 'GitLab'
                    url "${System.getenv('CI_API_V4_URL')}/projects/${System.getenv('CI_PROJECT_ID')}/packages/maven"
                    credentials(HttpHeaderCredentials) {
                        name "Job-Token"
                        value System.getenv('CI_JOB_TOKEN')
                    }
                    authentication {
                        header(HttpHeaderAuthentication)
                    }
                }
            }
        }
    
    Georg Seibt's avatar
    Georg Seibt committed
    }
    
    license {
        header = file('LICENSE_HEADER')
        strictCheck = true
    
    Georg Seibt's avatar
    Georg Seibt committed
    }