aboutsummaryrefslogtreecommitdiff
path: root/build.gradle
blob: cb11dcb8354d5cdbf1dc335eb7559f8c55c7eccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
    }
}

plugins {
  id 'java-library'
  id 'maven-publish'
  id 'eclipse'
  id 'net.minecrell.licenser' version '0.3'
}

group = 'net.minecraftforge'

version = gitVersion()
println('Version: ' + version + ' Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))

sourceSets {
    api
    shared
    gradlecomp
    java9
}

repositories {
    jcenter()
    mavenCentral()
}

configurations {
    sharedImplementation.extendsFrom apiImplementation
    gradlecompImplementation.extendsFrom sharedImplementation

    compile.extendsFrom sharedImplementation
    compile.extendsFrom gradlecompImplementation
}

dependencies {
    java9Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava }
    
    sharedImplementation sourceSets.api.output

    gradlecompImplementation sourceSets.shared.output
    gradlecompImplementation gradleApi()
    gradlecompImplementation 'com.google.guava:guava:30.1-jre'

    compile sourceSets.api.output
    compile sourceSets.shared.output
    compile sourceSets.gradlecomp.output
}


tasks.withType(JavaCompile) {
    options.encoding = 'utf-8'
    options.deprecation = true
}
java {
    toolchain.languageVersion = JavaLanguageVersion.of(8)
}

project(':artifactural9') {
    apply plugin: 'java'
    apply plugin: 'eclipse'
    group = rootProject.group
    java.toolchain.languageVersion = JavaLanguageVersion.of(9)

    sourceSets {
        java9.java.srcDirs = [rootProject.file('src/java9').getAbsolutePath()]
    }
    
    eclipse {
        project {
            name rootProject.name + '9'
            linkedResource name: 'java9', type: '2', location: rootProject.file('src/java9').getAbsolutePath()
        }
        jdt {
            sourceCompatibility = targetCompatibility = 9
        }
    }
    
    tasks.withType(JavaCompile) {
        options.encoding = 'utf-8'
        javaCompiler = javaToolchains.compilerFor {
            languageVersion = JavaLanguageVersion.of(9)
        }
    }
}



jar {
    from sourceSets.api.output
    from sourceSets.shared.output
    from(sourceSets.gradlecomp.output)

    into('META-INF/versions/9') {
        from project(':artifactural9').sourceSets.java9.output
    }
    
    manifest {
        attributes(
            'Multi-Release': 'true'
        )
    }
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.api.allSource
    from sourceSets.shared.allSource
    from sourceSets.gradlecomp.allSource
}


license {
    header = file("$rootDir/LICENSE-header.txt")
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact tasks.sourcesJar
            pom {
                groupId = project.group
                version = project.version
                artifactId = project.archivesBaseName
                name = project.archivesBaseName
                packaging = 'jar'
                description = 'A Gradle artifact processing and management tool'
                url = 'https://github.com/MinecraftForge/Artifactural/'

                scm {
                    url = 'https://github.com/MinecraftForge/Artifactural/'
                    connection = 'scm:git:git://github.com/MinecraftForge/Artifactural.git'
                    developerConnection = 'scm:git:git@github.com:MinecraftForge/Artifactural.git'
                }
                issueManagement {
                    system = 'github'
                    url = 'https://github.com/MinecraftForge/Artifactural/issues'
                }
                licenses {
                    license {
                        name = 'LGPL-2.1'
                        url = 'https://www.gnu.org/licenses/lgpl-2.1.txt'
                        distribution = 'repo'
                    }
                }
            }
        }
    }
    repositories {
        maven {
            if (project.hasProperty('mavenPassword')) {
                credentials {
                    username = project.properties.mavenUser
                    password = project.properties.mavenPassword
                }
                url 'https://files.minecraftforge.net/maven/manage/upload'
            } else {
                url 'file://' + rootProject.file('repo').getAbsolutePath()
            }
        }
    }
}

def gitInfo(dir) {
    String.metaClass.rsplit = { String del, int limit = -1 ->
        def lst = new ArrayList()
        def x = 0, idx
        def tmp = delegate
        while ((idx = tmp.lastIndexOf(del)) != -1 && (limit == -1 || x++ < limit)) {
            lst.add(0, tmp.substring(idx + del.length(), tmp.length()))
            tmp = tmp.substring(0, idx)
        }
        lst.add(0, tmp)
        return lst
    }
    
    def git = null
    try {
        git = org.eclipse.jgit.api.Git.open(dir)
    } catch (org.eclipse.jgit.errors.RepositoryNotFoundException e) {
        return [
            tag: '0.0',
            offset: '0',
            hash: '00000000',
            branch: 'master',
            commit: '0000000000000000000000',
            abbreviatedId: '00000000'
        ]
    }
    def desc = git.describe().setLong(true).setTags(true).call().rsplit('-', 2)
    def head = git.repository.exactRef('HEAD')
    def longBranch = head.symbolic ? head?.target?.name : null // matches Repository.getFullBranch() but returning null when on a detached HEAD

    def ret = [:]
    ret.tag = desc[0]
    ret.offset = desc[1]
    ret.hash = desc[2]
    ret.branch = longBranch != null ? org.eclipse.jgit.lib.Repository.shortenRefName(longBranch) : null
    ret.commit = org.eclipse.jgit.lib.ObjectId.toString(head.objectId)
    ret.abbreviatedId = head.objectId.abbreviate(8).name()
    
    return ret
}

def gitVersion() {
    def info = gitInfo(rootProject.file('.'))
    def branch = info.branch
    if (branch != null && branch.startsWith('pulls/'))
        branch = 'pr' + branch.rsplit('/', 1)[1]
    if (branch in [null, 'master', 'HEAD'])
        return "${info.tag}.${info.offset}".toString()
    return "${info.tag}.${info.offset}-${branch}".toString()
}