Skip to content

Commit 592db88

Browse files
committed
Refactor buildscript, and use JenkinsFile.
1 parent 89286ac commit 592db88

File tree

3 files changed

+138
-78
lines changed

3 files changed

+138
-78
lines changed

Jenkinsfile

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@Library('forge-shared-library')_
2+
3+
pipeline {
4+
agent {
5+
docker {
6+
image 'gradlewrapper:latest'
7+
args '-v gradlecache:/gradlecache'
8+
}
9+
}
10+
environment {
11+
GRADLE_ARGS = '-Dorg.gradle.daemon.idletimeout=5000'
12+
}
13+
14+
stages {
15+
stage('fetch') {
16+
steps {
17+
git(url: 'https://github.com/ModCoderPack/MCInjector.git', changelog: true)
18+
}
19+
}
20+
stage('buildandtest') {
21+
steps {
22+
sh './gradlew ${GRADLE_ARGS} --refresh-dependencies --continue build test'
23+
script {
24+
env.MYVERSION = sh(returnStdout: true, script: './gradlew properties -q | grep "version:" | awk \'{print $2}\'').trim()
25+
}
26+
}
27+
post {
28+
success {
29+
writeChangelog(currentBuild, 'build/changelog.txt')
30+
archiveArtifacts artifacts: 'build/changelog.txt', fingerprint: false
31+
}
32+
}
33+
}
34+
stage('publish') {
35+
when {
36+
not {
37+
changeRequest()
38+
}
39+
}
40+
environment {
41+
FORGE_MAVEN = credentials('forge-maven-mcp-user')
42+
}
43+
steps {
44+
sh './gradlew ${GRADLE_ARGS} publish -PmavenUser=${FORGE_MAVEN_USR} -PmavenPassword=${FORGE_MAVEN_PSW}'
45+
sh 'curl --user ${FORGE_MAVEN} http://files.minecraftforge.net/maven/manage/promote/latest/net.minecraftforge.mapping-verifier/${BUILD_NUMBER}'
46+
}
47+
}
48+
}
49+
post {
50+
always {
51+
archiveArtifacts artifacts: 'build/libs/**/*.jar', fingerprint: true
52+
//junit 'build/test-results/*/*.xml'
53+
//jacoco sourcePattern: '**/src/*/java'
54+
}
55+
}
56+
}

build.gradle

+81-77
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
jcenter()
5-
}
6-
dependencies {
7-
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
8-
}
1+
plugins {
2+
id 'net.minecrell.licenser' version '0.3'
3+
id 'org.ajoberstar.grgit' version '2.3.0'
4+
id 'com.github.johnrengelman.shadow' version '2.0.4'
95
}
106

11-
apply plugin: 'com.github.johnrengelman.shadow'
127
apply plugin: 'java'
138
apply plugin: 'eclipse'
149
apply plugin: 'maven'
10+
apply plugin: 'maven-publish'
1511

1612
group = 'de.oceanlabs.mcp'
17-
version = '3.7-SNAPSHOT'
18-
targetCompatibility = sourceCompatibility = '1.8'
19-
compileJava {
20-
sourceCompatibility = targetCompatibility = '1.8'
13+
version = gitVersion()
14+
targetCompatibility = sourceCompatibility = compileJava.targetCompatibility = compileJava.sourceCompatibility = '1.8'
15+
16+
ext {
17+
CHANGELOG = file("build/${project.name}-${project.version}-changelog.txt")
2118
}
2219

2320
repositories {
2421
mavenCentral()
2522
}
2623

24+
def gitVersion() {
25+
def desc = grgit.describe(longDescr: true).split('-') as List
26+
def hash = desc.remove(desc.size() - 1)
27+
def offset = desc.remove(desc.size() - 1)
28+
def tag = desc.join('-')
29+
def branch = grgit.branch.current().name
30+
return "${tag}.${offset}${t -> if (branch != 'master') t << '-' + branch}"
31+
}
32+
2733
jar {
2834
manifest.attributes('Main-Class': 'de.oceanlabs.mcp.mcinjector.MCInjector')
2935
manifest.attributes('Implementation-Version': project.version)
@@ -38,83 +44,81 @@ artifacts {
3844
archives jar
3945
archives shadowJar
4046
}
47+
def changelog = file('build/changelog.txt')
48+
def changelog_named = CHANGELOG
49+
if (changelog.exists()) {
50+
CHANGELOG.write(changelog.text)
51+
artifacts.archives CHANGELOG
52+
}
4153

4254
dependencies {
4355
compile 'org.ow2.asm:asm:6.1-beta2'
4456
compile 'org.ow2.asm:asm-tree:6.1-beta2'
4557
compile 'net.sf.jopt-simple:jopt-simple:4.9'
4658
compile 'com.google.code.gson:gson:2.2.4'
4759
}
48-
configurations { deployJars }
49-
uploadArchives {
50-
repositories {
51-
add project.repositories.mavenLocal()
52-
}
53-
repositories.mavenDeployer {
54-
configuration = configurations.deployJars
55-
56-
if (project.hasProperty('mavenPass')) {
57-
logger.info('Publishing to files server')
58-
repository(url: 'http://files.minecraftforge.net/maven/manage/upload') {
59-
authentication(userName: 'mcp', password: project.getProperty('mavenPass'))
60-
}
61-
} else {
62-
logger.info('Publishing to repo folder')
63-
repository(url: 'file://localhost/' + project.file('repo').getAbsolutePath())
64-
}
65-
66-
pom {
67-
groupId = project.group
68-
version = project.version
69-
artifactId = project.archivesBaseName
70-
}
71-
pom.project {
72-
name project.archivesBaseName
73-
packaging 'jar'
74-
description 'Java class metadata injector'
75-
url 'https://github.com/ModCoderPack/MCInjector'
7660

77-
scm {
78-
url 'https://github.com/ModCoderPack/MCInjector'
79-
connection 'scm:git:git://github.com/ModCoderPack/MCInjector.git'
80-
developerConnection 'scm:git:[email protected]:ModCoderPack/MCInjector.git'
81-
}
82-
83-
issueManagement {
84-
system 'github'
85-
url 'https://github.com/ModCoderPack/MCInjector/issues'
86-
}
87-
88-
licenses {
89-
license {
90-
name ''
91-
url ''
92-
distribution 'repo'
61+
publishing {
62+
publications {
63+
mavenJava(MavenPublication) {
64+
from components.java
65+
artifact shadowJar
66+
if (CHANGELOG.exists())
67+
artifact source: CHANGELOG, classifier: 'changelog'
68+
pom {
69+
name = 'MCInjector'
70+
description = 'Utility for cleaning up Minecraft jar files for decompolation'
71+
url = 'https://github.com/ModCoderPack/MCInjector'
72+
scm {
73+
url = 'https://github.com/ModCoderPack/MCInjector'
74+
connection = 'scm:git:git://github.com/ModCoderPack/MCInjector.git'
75+
developerConnection = 'scm:git:[email protected]:ModCoderPack/MCInjector.git'
9376
}
94-
}
95-
96-
developers {
97-
developer {
98-
id 'Fesh0r'
99-
name 'Fesh0r'
100-
roles { role 'developer' }
77+
issueManagement {
78+
system = 'github'
79+
url = 'https://github.com/ModCoderPack/MCInjector/issues'
10180
}
102-
developer {
103-
id 'Searge'
104-
name 'Searge'
105-
roles { role 'developer' }
81+
82+
developers {
83+
developer {
84+
id = 'Fesh0r'
85+
name = 'Fesh0r'
86+
}
87+
developer {
88+
id = 'Searge'
89+
name = 'Searge'
90+
}
91+
developer {
92+
id = 'cpw'
93+
name = 'cpw'
94+
}
95+
developer {
96+
id = 'LexManos'
97+
name = 'Lex Manos'
98+
}
10699
}
107-
developer {
108-
id 'cpw'
109-
name 'cpw'
110-
roles { role 'developer' }
100+
101+
licenses { //TODO: Ask the guys if I can license LGPL2.1 like everything else.
102+
license {
103+
name = ''
104+
url = ''
105+
distribution = 'repo'
106+
}
111107
}
112-
developer {
113-
id 'LexManos'
114-
name 'Lex Manos'
115-
roles { role 'developer' }
108+
}
109+
}
110+
}
111+
repositories {
112+
maven {
113+
if (project.hasProperty('mavenPassword')) {
114+
credentials {
115+
username = project.properties.mavenUser
116+
password = project.properties.mavenPassword
116117
}
118+
url 'http://files.minecraftforge.net/maven/manage/upload'
119+
} else {
120+
url 'file://' + project.file('repo').getAbsolutePath()
117121
}
118122
}
119123
}
120-
}
124+
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-bin.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip

0 commit comments

Comments
 (0)