Skip to content

Commit

Permalink
Build empty jars for hamcrest-core and -library. (#236)
Browse files Browse the repository at this point in the history
Existing maven builds that depend upon either `hamcrest-core-1.3.jar`
or `hamcrest-library.jar` will not upgrade their version for a pom-only
artifact. This change re-introduces a jar file for -core and -library,
but with no real classes. This allows Maven builds to correctly detect
the latest version of the jar. The transitive dependency on `hamcrest.jar`
brings in the latest version of the classes that were previously in
both `hamcrest-core.jar` or `hamcrest-library.jar`.
  • Loading branch information
tumbarumba authored Nov 29, 2018
1 parent 50199a7 commit 0da9088
Show file tree
Hide file tree
Showing 164 changed files with 102 additions and 47 deletions.
44 changes: 12 additions & 32 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ version = "2.1-SNAPSHOT"

subprojects {
apply plugin: 'java-library'
apply plugin: 'osgi'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7


group = rootProject.group
version = rootProject.version

repositories {
Expand All @@ -24,19 +24,6 @@ subprojects {
}
}

jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Vendor': 'hamcrest.org',
'Implementation-Version': version,
'Automatic-Module-Name': 'org.hamcrest'
instruction 'Import-Package', '''javax.xml.namespace; resolution:=optional,
javax.xml.xpath; resolution:=optional,
org.w3c.dom; resolution:=optional,
*'''
}
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
Expand Down Expand Up @@ -83,13 +70,6 @@ def pomConfigurationFor(String pomName, String pomDescription) {
}
}

def appendDependency(Object dependencies, String artifactId) {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', 'org.hamcrest')
dependency.appendNode('artifactId', artifactId)
dependency.appendNode('version', rootProject.version)
}

def publishToOssrh = project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')

publishing {
Expand All @@ -105,26 +85,26 @@ publishing {
'Core API and libraries of hamcrest matcher framework.')
}

def hamcrestCoreProject = project(':hamcrest-core')
hamcrestCore(MavenPublication) {
artifactId 'hamcrest-core'
from hamcrestCoreProject.components.java
artifactId hamcrestCoreProject.name
artifact hamcrestCoreProject.sourcesJar
artifact hamcrestCoreProject.javadocJar
pom pomConfigurationFor(
'Hamcrest Core',
'Core Hamcrest API - deprecated, please use "hamcrest" instead')
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
appendDependency(dependencies, 'hamcrest')
}
}

def hamcrestLibraryProject = project(':hamcrest-library')
hamcrestLibrary(MavenPublication) {
artifactId 'hamcrest-library'
from hamcrestLibraryProject.components.java
artifactId hamcrestLibraryProject.name
artifact hamcrestLibraryProject.sourcesJar
artifact hamcrestLibraryProject.javadocJar
pom pomConfigurationFor(
'Hamcrest Library',
'A library of Hamcrest matchers - deprecated, please use "hamcrest" instead')
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
appendDependency(dependencies, 'hamcrest-core')
}
}
}
repositories {
Expand Down
18 changes: 18 additions & 0 deletions hamcrest-core/hamcrest-core.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
dependencies {
api project(':hamcrest')
}

jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Vendor': 'hamcrest.org',
'Implementation-Version': version,
'Automatic-Module-Name': 'org.hamcrest'
}
}

javadoc {
title = "Hamcrest Core $version API"
options.showFromPackage()
options.showFromPrivate()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hamcrest;

/**
* All the classes in <code>hamcrest-core.jar</code> have moved to
* <code>hamcrest.jar</code>. Please use that dependency instead.
*/
@Deprecated
class HamcrestCoreIsDeprecated {
}
5 changes: 5 additions & 0 deletions hamcrest-core/src/main/java/org/hamcrest/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* All classes in <code>hamcrest-core.jar</code> have been migrated to
* <code>hamcrest.jar</code>. Please use that dependency instead.
*/
package org.hamcrest;
5 changes: 5 additions & 0 deletions hamcrest-core/src/main/resources/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hamcrest Core
=============

All the classes in hamcrest-core.jar and hamcrest-library.jar has moved
into hamcrest.jar. Please update your dependencies.
17 changes: 17 additions & 0 deletions hamcrest-library/hamcrest-library.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dependencies {
api project(':hamcrest-core')
}

jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Vendor': 'hamcrest.org',
'Implementation-Version': version,
'Automatic-Module-Name': 'org.hamcrest'
}
}

javadoc {
title = "Hamcrest Library $version API"
options.showFromPackage()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hamcrest;

/**
* All the classes in <code>hamcrest-library.jar</code> have moved to
* <code>hamcrest.jar</code>. Please use that dependency instead.
*/
@Deprecated
class HamcrestLibraryIsDeprecated {
}
5 changes: 5 additions & 0 deletions hamcrest-library/src/main/java/org/hamcrest/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* All classes in <code>hamcrest-library.jar</code> have been migrated to
* <code>hamcrest.jar</code>. Please use that dependency instead.
*/
package org.hamcrest;
5 changes: 5 additions & 0 deletions hamcrest-library/src/main/resources/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hamcrest Library
================

All the classes in hamcrest-core.jar and hamcrest-library.jar has moved
into hamcrest.jar. Please update your dependencies.
30 changes: 15 additions & 15 deletions hamcrest/hamcrest.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
version = rootProject.version
apply plugin: 'osgi'

sourceSets {
main {
java {
srcDirs rootProject.file('hamcrest-core/src/main/java'),
rootProject.file('hamcrest-library/src/main/java')
}
}
test {
java {
srcDirs rootProject.file('hamcrest-core/src/test/java'),
rootProject.file('hamcrest-library/src/test/java')
}
}
}
version = rootProject.version

dependencies {
testImplementation(group: 'junit', name: 'junit', version: '4.12') {
transitive = false
}
}

jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Vendor': 'hamcrest.org',
'Implementation-Version': version,
'Automatic-Module-Name': 'org.hamcrest'
instruction 'Import-Package', '''javax.xml.namespace; resolution:=optional,
javax.xml.xpath; resolution:=optional,
org.w3c.dom; resolution:=optional,
*'''
}
}

javadoc.title = "Hamcrest $version API"
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
enableFeaturePreview('STABLE_PUBLISHING')

include 'hamcrest',
'hamcrest-core',
'hamcrest-library',
'hamcrest-integration'

rootProject.name = 'JavaHamcrest'
Expand Down

0 comments on commit 0da9088

Please sign in to comment.