Skip to content

Commit 0f7a3b2

Browse files
committed
Migrate build system from Maven to Gradle
The main motivation for migrating to Gradle is the build duration. With the introduction of the new multi-module project structure build times of the Maven-based build increased heavily. Tests showed that Gradle can build the project much faster. In addition to reducing build times, Gradle allows to better minimize code duplication in build scripts: Maven's solution for centralising build configuration in a multi-module project are parent modules. The disadvantage of this solution is that the parent modules need to be published along with the actual artifacts. These additional publications, which are technically only required for building the artifacts, are a source of confusion for users. Other than Maven Gradle clearly separates the organisation of the build scripts from the published dependency information. This enables us to coveniently organise the build scripts while at the same time only publish the actual artifacts. Gradle's philosophy for configuring a build also opens new options for organising the release process.
1 parent cffc5b9 commit 0f7a3b2

File tree

150 files changed

+1463
-2503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+1463
-2503
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Ignore temporary maven files:
22
target/
33

4+
# Ignore temporary gradle files:
5+
.gradle
6+
.gradletasknamecache
7+
build
8+
49
# Ignore Eclipse project files:
510
.checkstyle
611
.pmd
@@ -15,6 +20,11 @@ target/
1520
*.iml
1621
.idea
1722
/out/
23+
/*/out/
1824

1925
# Ignore IntelliJ JIRA plugin
2026
atlassian-ide-plugin.xml
27+
28+
# Ignore files generated by CI:
29+
buildbot.keyring
30+

.travis.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
language: java
21
sudo: false
2+
dist: trusty
3+
language: java
34
jdk:
45
- oraclejdk8
56

6-
env:
7-
global:
8-
- secure: "V5OtkOZRRjjep5ig8A/z9hVOCPYJZRyuPjQ1bmGgtjtzPuLS4x5FSBHLZ+OERdR8VS3nJh05UoNVvxS6tdQ3pbIoJUojbNEFCABGVI+krvsbbar7nDZiF9yKI4mxP60sPvlD7gQ0n0Bdq1BpZGqHmwESsocAMd24oZi+8Nj80sk="
9-
- secure: "T9FcW2f0orue6i+Pvc1hE64mSoyOSwJFL9OrCBmhom5QW51Q8gP71DpEIz8fc6MvvU3wpSbTg5+lvbnTRdQCxmQzBeZb4yfdwUElldxaBqQaqVJWYBfoz0T1iznNA9WV3kHoHiDcb0iy3w/yzDxieQWjwj/69lKCvn8o425se7E="
10-
117
after_success:
12-
- "[[ $TRAVIS_BRANCH == \"master\" ]] && { python travis-ci/configure-mvn.py ; mvn clean deploy --settings ~/.m2/mySettings.xml -Dgpg.skip=true -P deploy ; }"
8+
- ./travis/publish.sh
9+

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,21 @@ TODO: Add
6161

6262
# Building metafacture-core from source
6363

64-
Building metafacture-core from source is easy. All you need is git and [maven](http://maven.apache.org/):
64+
Building metafacture-core from source is easy. All you need is git and JDK 8:
6565

66-
1. Clone the metafacture-core repository:
66+
1. Clone the metafacture-core repository and change into the directory:
6767

68-
$ git clone https://github.com/culturegraph/metafacture-core.git
68+
```bash
69+
$ git clone https://github.com/culturegraph/metafacture-core.git
70+
$ cd metafacture-core
71+
```
6972

70-
2. Build and install in your local repository:
73+
2. Invoke the gradle-wrapper to download Gradle and build metafacture-core:
7174

72-
$ mvn clean install
73-
74-
It is important to perform this step *before* importing the project into your IDE because it generates the lexer and parser sources for Flux from antlr grammar definitions. Otherwise your IDE will fail to compile the sources if it has integrated background compilation (like Eclipse has, for instance).
75+
```bash
76+
$ ./gradlew install
77+
```
78+
on Windows call `gradlew.bat install` instead.
7579

7680
See [Code Quality and Style](https://github.com/culturegraph/metafacture-core/wiki/Code-Quality-and-Style) on the wiki for further information on the sources.
7781

build.gradle

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/*
2+
* Copyright 2017 Christoph Böhme
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.util.regex.Matcher
18+
19+
plugins {
20+
id 'org.ajoberstar.grgit' version '2.0.0-rc.1'
21+
}
22+
23+
ext.gitTag = getGitTag()
24+
25+
allprojects {
26+
group = 'org.culturegraph'
27+
version = getVersionFrom(rootProject.ext.gitTag) ?: '5.0.0-SNAPSHOT'
28+
ext.mavenName = null
29+
}
30+
31+
configure(subprojects.findAll { it.name != 'metafacture-runner' }) {
32+
apply plugin: 'java-library'
33+
}
34+
35+
project(':metafacture-runner') {
36+
apply plugin: 'java'
37+
}
38+
39+
subprojects {
40+
apply plugin: 'signing'
41+
apply plugin: 'maven'
42+
43+
sourceCompatibility = 1.8
44+
targetCompatibility = 1.8
45+
46+
tasks.withType(JavaCompile) {
47+
options.encoding = 'UTF-8'
48+
}
49+
50+
task sourceJar(type: Jar) {
51+
dependsOn tasks.classes
52+
from sourceSets.main.allJava
53+
classifier 'sources'
54+
description 'Creates a jar containing the source files of this project.'
55+
group 'build'
56+
}
57+
58+
task javadocJar(type: Jar) {
59+
dependsOn tasks.javadoc
60+
from tasks.javadoc
61+
classifier 'javadoc'
62+
description 'Creates a jar containing the javadoc of this project.'
63+
group 'build'
64+
}
65+
66+
task publish {
67+
dependsOn tasks.uploadArchives
68+
}
69+
70+
configurations {
71+
mavenDeploySupport
72+
}
73+
74+
dependencies {
75+
mavenDeploySupport "org.apache.maven.wagon:wagon-http:2.2"
76+
}
77+
78+
artifacts {
79+
archives sourceJar
80+
archives javadocJar
81+
}
82+
83+
signing {
84+
required {
85+
rootProject.ext.gitTag != null &&
86+
gradle.taskGraph.hasTask(tasks.uploadArchives)
87+
}
88+
sign configurations.archives
89+
}
90+
91+
def mavenProjectDescription = {
92+
name project.ext.mavenName ?: project.name
93+
if (project.description) {
94+
description project.description
95+
}
96+
url 'https://github.com/culturegraph/metafacture-core'
97+
inceptionYear '2011'
98+
organization {
99+
name 'Deutsche Nationalbibliothek'
100+
url 'http://dnb.de/'
101+
}
102+
licenses {
103+
license {
104+
name 'The Apache License, Version 2.0'
105+
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
106+
}
107+
}
108+
mailingLists {
109+
mailingList {
110+
name 'Metafacture Mailing List'
111+
112+
subscribe '[email protected]'
113+
unsubscribe '[email protected]'
114+
archive 'http://lists.dnb.de/pipermail/metafacture/'
115+
}
116+
}
117+
scm {
118+
connection 'scm:git:https://github.com/culturegraph/metafacture-core.git'
119+
developerConnection 'scm:git:https://github.com/culturegraph/metafacture-core.git'
120+
url 'https://github.com/culturegraph/metafacture-core'
121+
tag rootProject.ext.gitTag ?: 'HEAD'
122+
}
123+
issueManagement {
124+
system 'Github'
125+
url 'https://github.com/culturegraph/metafacture-core/issues'
126+
}
127+
ciManagement {
128+
system 'Travis CI'
129+
url 'https://travis-ci.org/culturegraph/metafacture-core'
130+
}
131+
}
132+
133+
install {
134+
repositories {
135+
mavenInstaller {
136+
pom.project mavenProjectDescription
137+
beforeDeployment {
138+
MavenDeployment deployment -> signing.signPom(deployment)
139+
}
140+
}
141+
}
142+
}
143+
144+
uploadArchives {
145+
repositories {
146+
mavenDeployer {
147+
configuration = configurations.mavenDeploySupport
148+
if (project.hasProperty('releaseRepositoryUrl')) {
149+
repository(url: releaseRepositoryUrl) {
150+
if (project.hasProperty('releaseRepositoryUser')) {
151+
authentication(userName: releaseRepositoryUser,
152+
password: releaseRepositoryPassword)
153+
}
154+
}
155+
}
156+
if (project.hasProperty('snapshotRepositoryUrl')) {
157+
snapshotRepository(url: snapshotRepositoryUrl) {
158+
if (project.hasProperty('snapshotRepositoryUser')) {
159+
authentication(userName: snapshotRepositoryUser,
160+
password: snapshotRepositoryPassword)
161+
}
162+
}
163+
}
164+
pom.project mavenProjectDescription
165+
beforeDeployment {
166+
MavenDeployment deployment -> signing.signPom(deployment)
167+
}
168+
}
169+
}
170+
}
171+
172+
repositories {
173+
mavenLocal()
174+
mavenCentral()
175+
}
176+
}
177+
178+
def getGitTag() {
179+
def tags = getGitTags(grgit)
180+
if (tags.isEmpty()) {
181+
logger.lifecycle("HEAD is not tagged. Making a snapshot build")
182+
return null
183+
}
184+
if (tags.size() > 1) {
185+
logger.warn("HEAD has ${tags.size()} tags. Making a snapshot build")
186+
return null
187+
}
188+
def tagName = tags[0].name
189+
logger.lifecycle("Found tag $tagName. Making a release build")
190+
return tagName
191+
}
192+
193+
def static getGitTags(grgit) {
194+
def tags = []
195+
for (tag in grgit.tag.list()) {
196+
if (tag.commit == grgit.head()) {
197+
tags.add tag
198+
}
199+
}
200+
return tags
201+
}
202+
203+
def static extractVersion(tag) {
204+
Matcher matcher =
205+
tag =~ /metafacture-core-(\d+\.\d+\.\d+(-[-A-Za-z0-9]+)?)/
206+
if (!matcher.matches()) {
207+
throw new GradleException("""\
208+
Unsupported tag format: $tag
209+
Could not extract version from tag. Supported tag formats are
210+
metafacture-core-X.Y.Z and
211+
metafacture-core-X.Y.Z-QUALIFIER
212+
""".stripIndent())
213+
}
214+
return matcher.group(1)
215+
}
216+
217+
def static getVersionFrom(tag) {
218+
if (tag != null) {
219+
return extractVersion(tag)
220+
}
221+
return null
222+
}

gradle/wrapper/gradle-wrapper.jar

53.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sun Jul 30 20:26:57 CEST 2017
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-all.zip

0 commit comments

Comments
 (0)