Skip to content

Commit 1cbb4d6

Browse files
author
Justin Ryan
committed
Fixing issue when publishing source/javadoc to maven central
1 parent 05c4d06 commit 1cbb4d6

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

gradle/convention.gradle

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,40 @@ subprojects { project ->
1414

1515
task sourcesJar(type: Jar, dependsOn:classes) {
1616
from sourceSets.main.allSource
17+
classifier 'sources'
18+
extension 'jar'
1719
}
1820

1921
task javadocJar(type: Jar, dependsOn:javadoc) {
2022
from javadoc.destinationDir
23+
classifier 'javadoc'
24+
extension 'jar'
2125
}
2226

2327
configurations.add('sources')
2428
configurations.add('javadoc')
29+
configurations.archives {
30+
extendsFrom configurations.sources
31+
extendsFrom configurations.javadoc
32+
}
33+
34+
// When outputing to an Ivy repo, we want to use the proper type field
35+
gradle.taskGraph.whenReady {
36+
def isNotMaven = !it.hasTask(project.uploadMavenCentral)
37+
if (isNotMaven) {
38+
def artifacts = project.configurations.sources.artifacts
39+
def sourceArtifact = artifacts.iterator().next()
40+
sourceArtifact.type = 'sources'
41+
}
42+
}
2543

2644
artifacts {
2745
sources(sourcesJar) {
28-
type 'source'
29-
classifier 'sources'
46+
// Weird Gradle quirk where type will be used for the extension, but only for sources
47+
type 'jar'
3048
}
3149
javadoc(javadocJar) {
3250
type 'javadoc'
33-
classifier 'javadoc'
3451
}
3552
}
3653

0 commit comments

Comments
 (0)