Skip to content
Snippets Groups Projects
Select Git revision
  • c35fbad71c8d47dc8b4858351940f0d99550a0e8
  • dev default protected
  • main protected
  • chore/using-handlebars
4 results

relast2uml.java-publishing-conventions.gradle

Blame
  • relast2uml.java-publishing-conventions.gradle 2.24 KiB
    plugins {
      id 'java'
      id 'idea'
      id 'com.github.ben-manes.versions'
      id 'maven-publish'
    }
    
    repositories {
      mavenCentral()
    }
    
    dependencies {
      testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${jupiter_version}"
      testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.18.1'
      testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jupiter_version}"
    }
    
    jar {
      from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
      }
    }
    
    def versionFile = "src/main/resources/${project.getName()}Version.properties"
    def oldProps = new Properties()
    
    try {
      file(versionFile).withInputStream { stream -> oldProps.load(stream) }
      version = oldProps['version']
    } catch (e) {
      // this happens, if either the properties file is not present, or cannot be read from
      throw new GradleException("File ${versionFile} not found or unreadable. Aborting.", e)
    }
    
    task printVersion() {
      doLast {
        println(version)
      }
    }
    
    task newVersion() {
      doFirst {
        def props = new Properties()
        props['version'] = value
        props.store(file(versionFile).newWriter(), null)
      }
    }
    
    task setDevVersionForCI() {
      doFirst {
        def props = new Properties()
        props['version'] = version + "-$System.env.CI_PIPELINE_IID"
        props.store(file(versionFile).newWriter(), null)
      }
    }
    
    //679
    publishing {
      publications {
        maven(MavenPublication) {
          groupId = 'de.tudresden.inf.st'
    //      from components.java
          artifact("build/libs/${project.getName()}-${project.getVersion()}.jar") {
              extension 'jar'
          }
        }
      }
      repositories {
        maven {
          url "https://git-st.inf.tu-dresden.de/api/v4/projects/679/packages/maven"
          // Uncomment the following lines to publish manually (and comment out the other credentials section)
    //            credentials(HttpHeaderCredentials) {
    //                name = "Private-Token"
    //                value = gitLabPrivateToken // the variable resides in ~/.gradle/gradle.properties
    //            }
          credentials(HttpHeaderCredentials) {
            name = 'Job-Token'
            value = System.getenv("CI_JOB_TOKEN")
          }
          authentication {
            header(HttpHeaderAuthentication)
          }
        }
    
      }
    }
    
    publish.dependsOn jar