Skip to content

Commit c9522e3

Browse files
authored
Build separate jars for core, library, and all. (hamcrest#228)
This is done by converting to a multi-project gradle build, with subprojects for `hamcrest-core.jar` and `hamcrest-library.jar`. The root project is responsible for combining all the individual jars into `hamcrest-all.jar`, as well as configuring the publishing.
1 parent 9c53a79 commit c9522e3

File tree

5 files changed

+156
-78
lines changed

5 files changed

+156
-78
lines changed

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/build
2-
/classes
3-
/bin
4-
/out
1+
build/
2+
classes/
3+
bin/
4+
out/
55
.DS_Store
66
*~
77
*.swp
8-
/.idea
8+
.idea/
99
*.iws
1010
*.ipr
1111
*.iml

build.gradle

Lines changed: 125 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,159 @@
1-
import static org.gradle.api.JavaVersion.VERSION_1_7
2-
3-
apply plugin: 'java'
4-
apply plugin: 'osgi'
51
apply plugin: 'signing'
2+
apply plugin: 'osgi'
63
apply plugin: 'maven-publish'
74

8-
sourceCompatibility = VERSION_1_7
9-
targetCompatibility = VERSION_1_7
10-
115
group = "org.hamcrest"
12-
version = "2.0.0.0"
6+
version = "1.4-SNAPSHOT"
137

8+
subprojects {
9+
apply plugin: 'java-library'
10+
apply plugin: 'osgi'
1411

15-
repositories {
16-
mavenCentral()
17-
}
12+
sourceCompatibility = JavaVersion.VERSION_1_7
13+
targetCompatibility = JavaVersion.VERSION_1_7
14+
15+
version = rootProject.version
1816

19-
dependencies {
20-
testCompile(group: 'junit', name: 'junit', version: '4.12') {
21-
transitive = false
17+
repositories {
18+
mavenCentral()
2219
}
23-
}
2420

25-
sourceSets {
26-
main {
27-
java {
28-
srcDirs 'hamcrest-core/src/main/java', 'hamcrest-library/src/main/java'
21+
test {
22+
testLogging {
23+
exceptionFormat = 'full'
2924
}
30-
3125
}
32-
test {
33-
java {
34-
srcDirs 'hamcrest-core/src/test/java', 'hamcrest-library/src/test/java'
26+
27+
jar {
28+
manifest {
29+
attributes 'Implementation-Title': project.name,
30+
'Implementation-Vendor': 'hamcrest.org',
31+
'Implementation-Version': version
32+
instruction 'Import-Package', '''javax.xml.namespace; resolution:=optional,
33+
javax.xml.xpath; resolution:=optional,
34+
org.w3c.dom; resolution:=optional,
35+
*'''
3536
}
3637
}
37-
}
3838

39-
test {
40-
testLogging {
41-
exceptionFormat = 'full'
39+
task sourcesJar(type: Jar) {
40+
classifier = 'sources'
41+
from sourceSets.main.allSource
42+
}
43+
44+
task javadocJar(type: Jar) {
45+
classifier = 'javadoc'
46+
from javadoc
4247
}
4348
}
4449

45-
jar {
50+
task allClassesJar(type: Jar, dependsOn: subprojects.tasks['build']) {
51+
baseName = 'hamcrest-all'
52+
subprojects.each { subproject ->
53+
from zipTree(subproject.jar.archivePath)
54+
}
4655
manifest {
4756
attributes 'Implementation-Title': 'hamcrest-all',
4857
'Implementation-Vendor': 'hamcrest.org',
4958
'Implementation-Version': version
50-
instruction 'Import-Package', '''javax.xml.namespace; resolution:=optional,
51-
javax.xml.xpath; resolution:=optional,
52-
org.w3c.dom; resolution:=optional,
53-
*'''
5459
}
5560
}
5661

57-
task sourcesJar(type: Jar) {
62+
63+
task allSourcesJar(type: Jar) {
64+
baseName = 'hamcrest-all'
5865
classifier = 'sources'
59-
from sourceSets.main.allSource
66+
subprojects.each { subproject ->
67+
from subproject.sourceSets.main.allSource
68+
}
6069
}
6170

62-
task javadocJar(type: Jar) {
71+
task allJavadoc(type: Javadoc) {
72+
group = 'Documentation'
73+
description = 'Generate combined Javadoc for all projects'
74+
title = "Hamcrest All $version API"
75+
subprojects.each { proj ->
76+
proj.tasks.withType(Javadoc).each { javadocTask ->
77+
source += javadocTask.source
78+
classpath += javadocTask.classpath
79+
excludes += javadocTask.excludes
80+
includes += javadocTask.includes
81+
}
82+
}
83+
}
84+
85+
task allJavadocJar(type: Jar) {
6386
classifier = 'javadoc'
64-
from javadoc
87+
from allJavadoc
88+
}
89+
90+
def pomConfigurationFor(String pomName, String pomDescription) {
91+
return {
92+
name = pomName
93+
description = pomDescription
94+
url = 'http://hamcrest.org/JavaHamcrest/'
95+
96+
scm {
97+
connection = 'git@github.com:hamcrest/JavaHamcrest.git'
98+
url = 'https://github.com/hamcrest/JavaHamcrest'
99+
}
100+
101+
licenses {
102+
license {
103+
name = 'BSD Licence 3'
104+
url = 'http://opensource.org/licenses/BSD-3-Clause'
105+
}
106+
}
107+
108+
developers {
109+
developer {
110+
id = 'joewalnes'
111+
name = 'Joe Walnes'
112+
}
113+
developer {
114+
id = 'npryce'
115+
name = 'Nat Pryce'
116+
}
117+
developer {
118+
id = 'sf105'
119+
name = 'Steve Freeman'
120+
}
121+
}
122+
}
65123
}
66124

67125
publishing {
68126
publications {
69-
mavenJava(MavenPublication) {
70-
artifactId = 'java-hamcrest'
71-
from components.java
72-
artifact sourcesJar
73-
artifact javadocJar
74-
pom {
75-
name = 'Java Hamcrest'
76-
description = 'Hamcrest matcher library for Java'
77-
url = 'http://hamcrest.org/JavaHamcrest/'
78-
79-
scm {
80-
connection = 'git@github.com:hamcrest/JavaHamcrest.git'
81-
url = 'https://github.com/hamcrest/JavaHamcrest'
82-
}
127+
def coreProject = project(':hamcrest-core')
128+
hamcrestCore(MavenPublication) {
129+
from coreProject.components.java
130+
artifactId coreProject.name
131+
artifact coreProject.sourcesJar
132+
artifact coreProject.javadocJar
133+
pom pomConfigurationFor(
134+
'Hamcrest Core',
135+
'This is the core API of hamcrest matcher framework to be used by third-party framework providers. This includes the a foundation set of matcher implementations for common operations.')
136+
}
83137

84-
licenses {
85-
license {
86-
name = 'BSD Licence 3'
87-
url = 'http://opensource.org/licenses/BSD-3-Clause'
88-
}
89-
}
138+
def libraryProject = project(':hamcrest-library')
139+
hamcrestLibrary(MavenPublication) {
140+
from libraryProject.components.java
141+
artifactId = libraryProject.name
142+
artifact libraryProject.sourcesJar
143+
artifact libraryProject.javadocJar
144+
pom pomConfigurationFor(
145+
'Hamcrest Library',
146+
'Hamcrest library of matcher implementations.')
147+
}
90148

91-
developers {
92-
developer {
93-
id = 'joewalnes'
94-
name = 'Joe Walnes'
95-
}
96-
developer {
97-
id = 'npryce'
98-
name = 'Nat Pryce'
99-
}
100-
developer {
101-
id = 'sf105'
102-
name = 'Steve Freeman'
103-
}
104-
}
105-
}
149+
hamcrestAll(MavenPublication) {
150+
artifactId = 'hamcrest-all'
151+
artifact allClassesJar
152+
artifact allSourcesJar
153+
artifact allJavadocJar
154+
pom pomConfigurationFor(
155+
'Hamcrest All',
156+
'A self-contained hamcrest jar containing all of the sub-modules in a single artifact.')
106157
}
107158
}
108159
repositories {
@@ -122,5 +173,7 @@ publishing {
122173

123174
signing {
124175
required { hasProperty('ossrhUsername') && hasProperty('ossrhPassword') }
125-
sign publishing.publications.mavenJava
176+
sign publishing.publications.hamcrestCore
177+
sign publishing.publications.hamcrestLibrary
178+
sign publishing.publications.hamcrestAll
126179
}

hamcrest-core/hamcrest-core.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dependencies {
2+
testImplementation(group: 'junit', name: 'junit', version: '4.12') {
3+
transitive = false
4+
}
5+
}
6+
7+
javadoc.title = "Hamcrest Core $version API"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dependencies {
2+
api project(':hamcrest-core')
3+
4+
testImplementation(group: 'junit', name: 'junit', version: '4.12') {
5+
transitive = false
6+
}
7+
testImplementation project(':hamcrest-core').sourceSets.test.output
8+
}
9+
10+
javadoc.title = "Hamcrest Library $version API"

settings.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
enableFeaturePreview('STABLE_PUBLISHING')
2-
rootProject.name = 'java-hamcrest'
2+
3+
include 'hamcrest-core',
4+
'hamcrest-library'
5+
6+
rootProject.name = 'hamcrest'
7+
8+
// Change the file name of the child project build file to match the directory name
9+
// This avoids having multiple `build.gradle` files, making them easier to distinguish
10+
rootProject.children.each { childProject -> childProject.buildFileName = "${childProject.name}.gradle" }

0 commit comments

Comments
 (0)