relast2uml.java-publishing-conventions.gradle 2.24 KB
Newer Older
René Schöne's avatar
René Schöne committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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}"
}

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
  }
René Schöne's avatar
René Schöne committed
47
48
}

49
50
51
52
53
54
55
56
task setDevVersionForCI() {
  doFirst {
    def props = new Properties()
    props['version'] = version + "-$System.env.CI_PIPELINE_IID"
    props.store(file(versionFile).newWriter(), null)
  }
}

René Schöne's avatar
René Schöne committed
57
58
59
60
61
//679
publishing {
  publications {
    maven(MavenPublication) {
      groupId = 'de.tudresden.inf.st'
62
63
64
65
//      from components.java
      artifact("build/libs/${project.getName()}-${project.getVersion()}.jar") {
          extension 'jar'
      }
René Schöne's avatar
René Schöne committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    }
  }
  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