Skip to content

Commit

Permalink
[publishing] fix pom configuration due to missing dependencies block. F…
Browse files Browse the repository at this point in the history
…ixes #202
  • Loading branch information
Andres Almiray committed Nov 29, 2019
1 parent d6ae2c0 commit d2ba804
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= kordamp-gradle-plugins
:linkattrs:
:project-name: kordamp-gradle-plugins
:plugin-version: 0.30.0
:plugin-version: 0.30.1

image:https://img.shields.io/travis/aalmiray/{project-name}/master.svg?logo=travis["Build Status", link="https://travis-ci.org/aalmiray/{project-name}"]
image:https://img.shields.io/badge/license-ASF2-blue.svg?logo=apache["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

group = org.kordamp.gradle
version = 0.30.0
version = 0.30.1
sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
*/
package org.kordamp.gradle.plugin.base.plugins.util

import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.artifacts.ExcludeRule
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.publish.Publication
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
Expand All @@ -46,6 +49,7 @@ import org.kordamp.gradle.plugin.base.model.Person
import org.kordamp.gradle.plugin.base.model.PomOptions

import static org.kordamp.gradle.PluginUtils.resolveEffectiveConfig
import static org.kordamp.gradle.PluginUtils.supportsApiConfiguration
import static org.kordamp.gradle.StringUtils.isBlank
import static org.kordamp.gradle.StringUtils.isNotBlank

Expand Down Expand Up @@ -145,6 +149,109 @@ class PublishingUtils {
})
}

static void configureDependencies(MavenPom pom, ProjectConfigurationExtension effectiveConfig, Project project) {
Closure<Boolean> filter = { org.gradle.api.artifacts.Dependency d ->
d.name != 'unspecified'
}

Map<String, org.gradle.api.artifacts.Dependency> compileDependencies = project.configurations.findByName('compile')
.allDependencies.findAll(filter)
.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] })

Map<String, org.gradle.api.artifacts.Dependency> runtimeDependencies = project.configurations.findByName('runtime')
.allDependencies.findAll(filter)
.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] })

Map<String, org.gradle.api.artifacts.Dependency> testDependencies = project.configurations.findByName('testRuntime')
.allDependencies.findAll(filter)
.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] })

if (supportsApiConfiguration(project)) {
compileDependencies.putAll(project.configurations.findByName('api')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
compileDependencies.putAll(project.configurations.findByName('implementation')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))

runtimeDependencies.putAll(project.configurations.findByName('runtimeOnly')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))

testDependencies.putAll(project.configurations.findByName('testImplementation')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
testDependencies.putAll(project.configurations.findByName('testRuntimeOnly')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
}

compileDependencies.keySet().each { key ->
runtimeDependencies.remove(key)
testDependencies.remove(key)
}
runtimeDependencies.keySet().each { key ->
testDependencies.remove(key)
}

if (compileDependencies || runtimeDependencies || testDependencies) {
injectDependencies(pom, project, compileDependencies, runtimeDependencies, testDependencies)
}
}

@CompileDynamic
private static void injectDependencies(MavenPom pom,
Project project,
Map<String, org.gradle.api.artifacts.Dependency> compileDependencies,
Map<String, org.gradle.api.artifacts.Dependency> runtimeDependencies,
Map<String, org.gradle.api.artifacts.Dependency> testDependencies) {
pom.withXml {
Node dependenciesNode = asNode().appendNode('dependencies')
compileDependencies.values().each { org.gradle.api.artifacts.Dependency dep ->
configureDependency(dependenciesNode.appendNode('dependency'), dep, project, 'compile')
}
runtimeDependencies.values().each { org.gradle.api.artifacts.Dependency dep ->
configureDependency(dependenciesNode.appendNode('dependency'), dep, project, 'runtime')
}
testDependencies.values().each { org.gradle.api.artifacts.Dependency dep ->
configureDependency(dependenciesNode.appendNode('dependency'), dep, project, 'test')
}
}
}

@CompileDynamic
private static void configureDependency(Node node, org.gradle.api.artifacts.Dependency dep, Project project, String scope) {
node.with {
appendNode('groupId', dep.group)
appendNode('artifactId', dep.name)
appendNode('version', dep.version)
appendNode('scope', scope)
if (isOptional(project, dep)) {
appendNode('optional', true)
}
}

if (dep instanceof ModuleDependency) {
ModuleDependency mdep = (ModuleDependency) dep
if (mdep.excludeRules.size() > 0) {
Node exclusions = node.appendNode('exclusions')
exclusions.with {
mdep.excludeRules.each { ExcludeRule rule ->
exclusions.appendNo('exclusion').with {
appendNode('groupId', rule.group)
appendNode('artifactId', rule.module)
}
}
}
}
}
}

@CompileDynamic
private static boolean isOptional(Project project, org.gradle.api.artifacts.Dependency dependency) {
project.findProperty('optionalDeps') && project.optionalDeps.contains(dependency)
}

static void configurePom(MavenPom pom, ProjectConfigurationExtension effectiveConfig, PomOptions pomOptions) {
pom.name.set(effectiveConfig.info.name)
pom.description.set(effectiveConfig.info.description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.gradle.api.tasks.TaskAction
import org.kordamp.gradle.plugin.base.ProjectConfigurationExtension

import static org.kordamp.gradle.PluginUtils.resolveEffectiveConfig
import static org.kordamp.gradle.PluginUtils.supportsApiConfiguration
import static org.kordamp.gradle.StringUtils.isNotBlank

/**
Expand Down Expand Up @@ -58,32 +59,37 @@ class MinpomTask extends DefaultTask {
d.name != 'unspecified'
}

Map<String, Dependency> compileDependencies = project.configurations.findByName('compile')
Map<String, org.gradle.api.artifacts.Dependency> compileDependencies = project.configurations.findByName('compile')
.allDependencies.findAll(filter)
.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] })
compileDependencies.putAll(project.configurations.findByName('api')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
compileDependencies.putAll(project.configurations.findByName('implementation')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))

Map<String, Dependency> runtimeDependencies = project.configurations.findByName('runtime')

Map<String, org.gradle.api.artifacts.Dependency> runtimeDependencies = project.configurations.findByName('runtime')
.allDependencies.findAll(filter)
.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] })
runtimeDependencies.putAll(project.configurations.findByName('runtimeOnly')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))

Map<String, Dependency> testDependencies = project.configurations.findByName('testRuntime')
Map<String, org.gradle.api.artifacts.Dependency> testDependencies = project.configurations.findByName('testRuntime')
.allDependencies.findAll(filter)
.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] })
testDependencies.putAll(project.configurations.findByName('testImplementation')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
testDependencies.putAll(project.configurations.findByName('testRuntimeOnly')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))

if (supportsApiConfiguration(project)) {
compileDependencies.putAll(project.configurations.findByName('api')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
compileDependencies.putAll(project.configurations.findByName('implementation')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))

runtimeDependencies.putAll(project.configurations.findByName('runtimeOnly')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))

testDependencies.putAll(project.configurations.findByName('testImplementation')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
testDependencies.putAll(project.configurations.findByName('testRuntimeOnly')
?.allDependencies.findAll(filter)
?.collectEntries({ [("${it.group}:${it.name}:${it.version}"): it] }))
}

compileDependencies.keySet().each { key ->
runtimeDependencies.remove(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,16 @@ class PublishingPlugin extends AbstractKordampPlugin {

if (!effectiveConfig.publishing.publications.contains('main') && !effectiveConfig.publishing.publications) {
main(MavenPublication) {
groupId = project.group
artifactId = project.name
version = project.version
try {
if (components.java) {
from components.java
}
} catch (Exception e) {
groupId = project.group
artifactId = project.name
version = project.version
PublishingUtils.configureDependencies(pom, effectiveConfig, project)
}

if (jar?.enabled) artifact jar
if (javadocJar?.enabled) artifact javadocJar
Expand Down

0 comments on commit d2ba804

Please sign in to comment.