@@ -270,7 +270,7 @@ class BuildPlugin implements Plugin<Project> {
270
270
271
271
// add exclusions to the pom directly, for each of the transitive deps of this project's deps
272
272
project. modifyPom { MavenPom pom ->
273
- pom. withXml(removeTransitiveDependencies (project))
273
+ pom. withXml(fixupDependencies (project))
274
274
}
275
275
}
276
276
@@ -299,9 +299,16 @@ class BuildPlugin implements Plugin<Project> {
299
299
}
300
300
}
301
301
302
- /* * Returns a closure which can be used with a MavenPom for removing transitive dependencies. */
303
- private static Closure removeTransitiveDependencies (Project project ) {
304
- // TODO: remove this when enforcing gradle 2.13+, it now properly handles exclusions
302
+ /**
303
+ * Returns a closure which can be used with a MavenPom for fixing problems with gradle generated poms.
304
+ *
305
+ * <ul >
306
+ * <li >Remove transitive dependencies (using wildcard exclusions, fixed in gradle 2.14)</li>
307
+ * <li >Set compile time deps back to compile from runtime (known issue with maven-publish plugin)
308
+ * </ul>
309
+ */
310
+ private static Closure fixupDependencies (Project project ) {
311
+ // TODO: remove this when enforcing gradle 2.14+, it now properly handles exclusions
305
312
return { XmlProvider xml ->
306
313
// first find if we have dependencies at all, and grab the node
307
314
NodeList depsNodes = xml. asNode(). get(' dependencies' )
@@ -315,6 +322,15 @@ class BuildPlugin implements Plugin<Project> {
315
322
String artifactId = depNode. get(' artifactId' ). get(0 ). text()
316
323
String version = depNode. get(' version' ). get(0 ). text()
317
324
325
+ // fix deps incorrectly marked as runtime back to compile time deps
326
+ // see https://discuss.gradle.org/t/maven-publish-plugin-generated-pom-making-dependency-scope-runtime/7494/4
327
+ boolean isCompileDep = project. configurations. compile. allDependencies. find { dep ->
328
+ dep. name == depNode. artifactId. text()
329
+ }
330
+ if (depNode. scope. text() == ' runtime' && isCompileDep) {
331
+ depNode. scope* . value = ' compile'
332
+ }
333
+
318
334
// collect the transitive deps now that we know what this dependency is
319
335
String depConfig = transitiveDepConfigName(groupId, artifactId, version)
320
336
Configuration configuration = project. configurations. findByName(depConfig)
@@ -327,17 +343,10 @@ class BuildPlugin implements Plugin<Project> {
327
343
continue
328
344
}
329
345
330
- // we now know we have something to exclude, so add the exclusion elements
331
- Node exclusions = depNode. appendNode(' exclusions' )
332
- for (ResolvedArtifact transitiveArtifact : artifacts) {
333
- ModuleVersionIdentifier transitiveDep = transitiveArtifact. moduleVersion. id
334
- if (transitiveDep. group == groupId && transitiveDep. name == artifactId) {
335
- continue ; // don't exclude the dependency itself!
336
- }
337
- Node exclusion = exclusions. appendNode(' exclusion' )
338
- exclusion. appendNode(' groupId' , transitiveDep. group)
339
- exclusion. appendNode(' artifactId' , transitiveDep. name)
340
- }
346
+ // we now know we have something to exclude, so add a wildcard exclusion element
347
+ Node exclusion = depNode. appendNode(' exclusions' ). appendNode(' exclusion' )
348
+ exclusion. appendNode(' groupId' , ' *' )
349
+ exclusion. appendNode(' artifactId' , ' *' )
341
350
}
342
351
}
343
352
}
@@ -349,7 +358,7 @@ class BuildPlugin implements Plugin<Project> {
349
358
publications {
350
359
all { MavenPublication publication -> // we only deal with maven
351
360
// add exclusions to the pom directly, for each of the transitive deps of this project's deps
352
- publication. pom. withXml(removeTransitiveDependencies (project))
361
+ publication. pom. withXml(fixupDependencies (project))
353
362
}
354
363
}
355
364
}
0 commit comments