diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPlugin.groovy index 8fcd405..0148fd0 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPlugin.groovy @@ -26,6 +26,7 @@ import org.gradle.api.publish.ivy.IvyModuleDescriptorDescription import org.gradle.api.publish.ivy.IvyModuleDescriptorSpec import org.gradle.api.publish.ivy.IvyPublication +@CompileDynamic class IvyBasePublishPlugin implements Plugin { @Override void apply(Project project) { @@ -55,73 +56,62 @@ class IvyBasePublishPlugin implements Plugin { */ PublishingExtension publishing = project.extensions.getByType(PublishingExtension) - publishing.publications(new Action() { + project.afterEvaluate(new Action() { @Override - void execute(PublicationContainer publications) { - publications.withType(IvyPublication) { IvyPublication publication -> - if (! project.state.executed) { - project.afterEvaluate(new Action() { - @Override - void execute(Project p) { - configureDescription(publication, project) - } - }) - } else { - configureDescription(publication, project) - } - - publication.descriptor(new Action() { - @Override - void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) { - ivyModuleDescriptorSpec.withXml(new Action() { + void execute(Project p) { + String status = p.status + String description = p.description ?: '' + publishing.publications(new Action() { + @Override + void execute(PublicationContainer publications) { + publications.withType(IvyPublication) { IvyPublication publication -> + publication.descriptor.status = status + publication.descriptor.description(new Action() { @Override - void execute(XmlProvider xml) { - configureXml(xml) + void execute(IvyModuleDescriptorDescription ivyModuleDescriptorDescription) { + ivyModuleDescriptorDescription.text.set(description) } }) - } - }) - } - } - }) - } - - @CompileDynamic - private void configureXml(XmlProvider xml) { - def root = xml.asNode() - def configurationsNode = root?.configurations - if(!configurationsNode) { - configurationsNode = root.appendNode('configurations') - } - else { - configurationsNode = configurationsNode[0] - } + publication.descriptor(new Action() { + @Override + void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) { + ivyModuleDescriptorSpec.withXml(new Action() { + @Override + void execute(XmlProvider xml) { + def root = xml.asNode() + def configurationsNode = root?.configurations + if (!configurationsNode) { + configurationsNode = root.appendNode('configurations') + } else { + configurationsNode = configurationsNode[0] + } - def minimalConfs = [ - compile: [], default: ['runtime', 'master'], javadoc: [], master: [], - runtime: ['compile'], sources: [], test: ['runtime'] - ] + def minimalConfs = [ + compile: [], default: ['runtime', 'master'], javadoc: [], master: [], + runtime: ['compile'], sources: [], test: ['runtime'] + ] - minimalConfs.each { minimal -> - def conf = configurationsNode.conf.find { it.@name == minimal.key } - if(!conf) { - conf = configurationsNode.appendNode('conf') - } - conf.@name = minimal.key - conf.@visibility = 'public' + minimalConfs.each { minimal -> + def conf = configurationsNode.conf.find { it.@name == minimal.key } + if (!conf) { + conf = configurationsNode.appendNode('conf') + } + conf.@name = minimal.key + conf.@visibility = 'public' - if(!minimal.value.empty) - conf.@extends = minimal.value.join(',') - } - } + if (!minimal.value.empty) + conf.@extends = minimal.value.join(',') + } + } + }) + } + }) + } + } + }) - private void configureDescription(IvyPublication publication, Project p) { - publication.descriptor.status = p.status - publication.descriptor.description(new Action() { - @Override - void execute(IvyModuleDescriptorDescription ivyModuleDescriptorDescription) { - ivyModuleDescriptorDescription.text.set(p.description ?: '') } }) + } } diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPlugin.groovy index 99f9fe2..e05ce35 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPlugin.groovy @@ -15,18 +15,19 @@ */ package nebula.plugin.publishing.ivy +import groovy.transform.Canonical import groovy.transform.CompileDynamic import org.gradle.api.Action import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.XmlProvider -import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaPlugin import org.gradle.api.publish.PublicationContainer import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.ivy.IvyModuleDescriptorSpec import org.gradle.api.publish.ivy.IvyPublication +@CompileDynamic class IvyCompileOnlyPlugin implements Plugin { static enum DependenciesContent { @@ -41,46 +42,57 @@ class IvyCompileOnlyPlugin implements Plugin { PublishingExtension publishing = project.extensions.getByType(PublishingExtension) project.plugins.withType(JavaPlugin) { JavaPlugin javaBasePlugin -> - - publishing.publications(new Action() { + project.afterEvaluate(new Action() { @Override - void execute(PublicationContainer publications) { - publications.withType(IvyPublication) { IvyPublication publication -> - publication.descriptor(new Action() { - @Override - void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) { - ivyModuleDescriptorSpec.withXml(new Action() { + void execute(Project p) { + def compileOnlyDependencies = project.configurations.compileOnly.incoming.dependencies.collect { + new Dependency(it.group, it.name, it.version) + } + + publishing.publications(new Action() { + @Override + void execute(PublicationContainer publications) { + publications.withType(IvyPublication) { IvyPublication publication -> + publication.descriptor(new Action() { @Override - void execute(XmlProvider xml) { - configureXml(project, xml) + void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) { + ivyModuleDescriptorSpec.withXml(new Action() { + @Override + void execute(XmlProvider xml) { + def root = xml.asNode() + def dependencies = compileOnlyDependencies + if (dependencies.size() > 0) { + def confs = root.configurations ? root.configurations[0] : root.appendNode('configurations') + confs.appendNode('conf', [name: 'provided', visibility: 'public']) + def deps = root.dependencies ? root.dependencies[0] : root.appendNode('dependencies') + dependencies.each { dep -> + def newDep = deps.appendNode('dependency') + newDep.@org = dep.organisation + newDep.@name = dep.module + newDep.@rev = dep.version + newDep.@conf = 'provided' + } + deps.children().sort(true, { + DependenciesContent.valueOf(it.name()).ordinal() + }) + } + } + }) } }) } - }) - } + } + }) } }) + } } - @CompileDynamic - private void configureXml(Project project, XmlProvider xml) { - def root = xml.asNode() - def dependencies = project.configurations.compileOnly.dependencies - if (dependencies.size() > 0) { - def confs = root.configurations ? root.configurations[0] : root.appendNode('configurations') - confs.appendNode('conf', [name: 'provided', visibility: 'public']) - def deps = root.dependencies ? root.dependencies[0] : root.appendNode('dependencies') - dependencies.each { dep -> - def newDep = deps.appendNode('dependency') - newDep.@org = dep.group - newDep.@name = dep.name - newDep.@rev = dep.version - newDep.@conf = 'provided' - } - deps.children().sort(true, { - DependenciesContent.valueOf(it.name()).ordinal() - }) - } + @Canonical + private static class Dependency { + String organisation + String module + String version } } diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/IvyManifestPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/IvyManifestPlugin.groovy index 28a7477..36f1352 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/IvyManifestPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/IvyManifestPlugin.groovy @@ -14,6 +14,7 @@ import org.gradle.api.publish.ivy.IvyPublication import static nebula.plugin.publishing.ManifestElementNameGenerator.* +@CompileDynamic class IvyManifestPlugin implements Plugin { @Override void apply(Project project) { @@ -38,7 +39,12 @@ class IvyManifestPlugin implements Plugin { ivyModuleDescriptorSpec.withXml(new Action() { @Override void execute(XmlProvider xml) { - configureXml(infoBroker, xml) + def desc = xml.asNode()?.info[0].description[0] + desc.'@xmlns:nebula' = 'http://netflix.com/build' + + infoBroker.buildManifest().each { key, value -> + desc.appendNode("nebula:${elementName(key)}", value) + } } }) } @@ -48,16 +54,4 @@ class IvyManifestPlugin implements Plugin { }) } } - - @CompileDynamic - private void configureXml(InfoBrokerPlugin infoBroker, XmlProvider xml) { - // the ivy info>description tag is the only one which can contain free - // text, including arbitrary xml - def desc = xml.asNode()?.info[0].description[0] - desc.'@xmlns:nebula' = 'http://netflix.com/build' - - infoBroker.buildManifest().each { key, value -> - desc.appendNode("nebula:${elementName(key)}", value) - } - } } diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPlugin.groovy index f727d0e..7ea8161 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPlugin.groovy @@ -26,27 +26,27 @@ class IvyNebulaPublishPlugin implements Plugin { project.ext.set(IVY_JAR, true) } - project.publishing { - publications { - nebulaIvy(IvyPublication) { - if (! project.state.executed) { - //configuration when STABLE_PUBLISHING is enabled - project.afterEvaluate { p -> - configurePublication(it, p) + project.afterEvaluate { p -> + def component = getComponent(p) + project.publishing { + publications { + nebulaIvy(IvyPublication) { publication -> + if(component) { + publication.from component } - } else { - configurePublication(it, project) } } } } } - private void configurePublication(IvyPublication publication, Project p) { - if (p.ext.get(IVY_WAR)) { - publication.from p.components.web - } else if (p.ext.get(IVY_JAR)) { - publication.from p.components.java + private getComponent(Project p) { + if(p.ext.get(IVY_WAR)) { + return p.components.web + } else if(p.ext.get(IVY_JAR)) { + return p.components.java + } else { + return null } } } diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemoveInvalidDependenciesPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemoveInvalidDependenciesPlugin.groovy index abc26c3..1220892 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemoveInvalidDependenciesPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemoveInvalidDependenciesPlugin.groovy @@ -31,6 +31,7 @@ import org.gradle.api.publish.ivy.IvyPublication * Removes from descriptor dependencies that are invalid: * 1) No revision available */ +@CompileDynamic class IvyRemoveInvalidDependenciesPlugin implements Plugin { @Override void apply(Project project) { @@ -45,7 +46,12 @@ class IvyRemoveInvalidDependenciesPlugin implements Plugin { ivyModuleDescriptorSpec.withXml(new Action() { @Override void execute(XmlProvider xml) { - configureXml(xml) + xml.asNode().dependencies.dependency.findAll() { Node dep -> + String revision = dep.@rev + if(!revision) { + dep.parent().remove(dep) + } + } } }) } @@ -54,14 +60,4 @@ class IvyRemoveInvalidDependenciesPlugin implements Plugin { } }) } - - @CompileDynamic - private void configureXml(XmlProvider xml) { - xml.asNode().dependencies.dependency.findAll() { Node dep -> - String revision = dep.@rev - if(!revision) { - dep.parent().remove(dep) - } - } - } } diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPlugin.groovy index 18ed4a6..4262537 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPlugin.groovy @@ -21,6 +21,7 @@ import org.gradle.api.Action import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.XmlProvider +import org.gradle.api.plugins.JavaPlugin import org.gradle.api.publish.PublicationContainer import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.ivy.IvyModuleDescriptorSpec @@ -30,58 +31,63 @@ import org.gradle.api.publish.ivy.IvyPublication /** * Removes from descriptor dependencies that have category status of platform or enhanced-platform */ +@CompileDynamic class IvyRemovePlatformDependenciesPlugin implements Plugin { @Override void apply(Project project) { PublishingExtension publishing = project.extensions.getByType(PublishingExtension) - publishing.publications(new Action() { + project.afterEvaluate(new Action() { @Override - void execute(PublicationContainer publications) { - publications.withType(IvyPublication) { IvyPublication publication -> - publication.descriptor(new Action() { + void execute(Project p) { + p.plugins.withType(JavaPlugin) { + def platformDependencies = PlatformDependencyVerifier.findPlatformDependencies(p) + publishing.publications(new Action() { @Override - void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) { - ivyModuleDescriptorSpec.withXml(new Action() { - @Override - void execute(XmlProvider xml) { - configureXml(project, xml) - } - }) - } - }) - } - } - }) - } + void execute(PublicationContainer publications) { + publications.withType(IvyPublication) { IvyPublication publication -> + publication.descriptor(new Action() { + @Override + void execute(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) { + ivyModuleDescriptorSpec.withXml(new Action() { + @Override + void execute(XmlProvider xml) { + xml.asNode().dependencies.dependency.findAll() { Node dep -> + String scope = dep.@conf + String group = dep.@org + String name = dep.@name - @CompileDynamic - private void configureXml(Project project, XmlProvider xml) { - xml.asNode().dependencies.dependency.findAll() { Node dep -> - String scope = dep.@conf - String group = dep.@org - String name = dep.@name + if (scope == 'compile->default') { + scope = 'compile' + } - if (scope == 'compile->default') { - scope = 'compile' - } + if (scope == 'provided->default' || scope == 'runtime->default') { + scope = 'runtime' + } - if (scope == 'provided->default' || scope == 'runtime->default') { - scope = 'runtime' - } + if (scope == 'test->default') { + scope = 'test' + } - if (scope == 'test->default') { - scope = 'test' - } + if (scope.contains('->')) { + scope = scope.split('->')[0] + } - if (scope.contains('->')) { - scope = scope.split('->')[0] - } + boolean isPlatformDependency = PlatformDependencyVerifier.isPlatformDependency(platformDependencies, scope, group, name) - boolean isPlatformDependency = PlatformDependencyVerifier.isPlatformDependency(project, scope, group, name) + if(isPlatformDependency) { + dep.parent().remove(dep) + } + } + } + }) + } + }) + } + } + }) + } - if(isPlatformDependency) { - dep.parent().remove(dep) } - } + }) } } diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/IvyVerifyUnspecifiedVersionDependenciesPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/IvyVerifyUnspecifiedVersionDependenciesPlugin.groovy index 4aea157..9d3c869 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/IvyVerifyUnspecifiedVersionDependenciesPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/IvyVerifyUnspecifiedVersionDependenciesPlugin.groovy @@ -27,6 +27,7 @@ import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.ivy.IvyModuleDescriptorSpec import org.gradle.api.publish.ivy.IvyPublication +@CompileDynamic class IvyVerifyUnspecifiedVersionDependenciesPlugin implements Plugin { @Override void apply(Project project) { @@ -41,7 +42,14 @@ class IvyVerifyUnspecifiedVersionDependenciesPlugin implements Plugin { ivyModuleDescriptorSpec.withXml(new Action() { @Override void execute(XmlProvider xml) { - verifyVersionsInDependencies(xml) + xml.asNode().dependencies.dependency.findAll() { Node dep -> + String revision = dep.@rev + if(revision == 'unspecified') { + String group = dep.@org + String name = dep.@name + throw new GradleException("Dependency $group:$name has an invalid version: $revision. This publication is invalid") + } + } } }) } @@ -51,15 +59,5 @@ class IvyVerifyUnspecifiedVersionDependenciesPlugin implements Plugin { }) } - @CompileDynamic - private void verifyVersionsInDependencies(XmlProvider xml) { - xml.asNode().dependencies.dependency.findAll() { Node dep -> - String revision = dep.@rev - if(revision == 'unspecified') { - String group = dep.@org - String name = dep.@name - throw new GradleException("Dependency $group:$name has an invalid version: $revision. This publication is invalid") - } - } - } + } diff --git a/src/main/groovy/nebula/plugin/publishing/ivy/PlatformDependencyVerifier.groovy b/src/main/groovy/nebula/plugin/publishing/ivy/PlatformDependencyVerifier.groovy index f227410..a82fe0a 100644 --- a/src/main/groovy/nebula/plugin/publishing/ivy/PlatformDependencyVerifier.groovy +++ b/src/main/groovy/nebula/plugin/publishing/ivy/PlatformDependencyVerifier.groovy @@ -35,18 +35,17 @@ class PlatformDependencyVerifier { private static final String REGULAR_PLATFORM = "platform" private static final String ENFORCED_PLATFORM = "enforced-platform" - static boolean isPlatformDependency(Project project, String scope, String group, String name) { - Boolean result = checkIfPlatformDependency(project, scope, group, name) + static boolean isPlatformDependency(def platformDependencies, String scope, String group, String name) { + Boolean result = checkIfPlatformDependency(platformDependencies, scope, group, name) Map scoping = [compile: 'runtime', provided: 'compileOnly'] if (!result && scoping[scope]) { - result = checkIfPlatformDependency(project, scoping[scope], group, name) + result = checkIfPlatformDependency(platformDependencies, scoping[scope], group, name) } result } - private static boolean checkIfPlatformDependency(Project project, String scope, String group, String name) { - def platformDependencies = findPlatformDependencies(project)[scope] - return platformDependencies.find { ComponentSelector componentSelector -> + private static boolean checkIfPlatformDependency(def platformDependencies, String scope, String group, String name) { + return platformDependencies.values().flatten().find { ComponentSelector componentSelector -> if(componentSelector instanceof ModuleComponentSelector) { return componentSelector.moduleIdentifier.group == group && componentSelector.moduleIdentifier.name == name } else if(componentSelector instanceof ProjectComponentSelector) { diff --git a/src/main/groovy/nebula/plugin/publishing/maven/MavenManifestPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/maven/MavenManifestPlugin.groovy index 90d069e..9d25b93 100644 --- a/src/main/groovy/nebula/plugin/publishing/maven/MavenManifestPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/maven/MavenManifestPlugin.groovy @@ -27,6 +27,7 @@ import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.MavenPublication import static nebula.plugin.publishing.ManifestElementNameGenerator.* +@CompileDynamic class MavenManifestPlugin implements Plugin { @Override void apply(Project project) { @@ -51,7 +52,13 @@ class MavenManifestPlugin implements Plugin { pom.withXml(new Action() { @Override void execute(XmlProvider xml) { - appendManifest(xml, infoBroker.buildManifest()) + def propertiesNode = xml.asNode()?.properties + if (!propertiesNode) { + propertiesNode = xml.asNode().appendNode('properties') + } + infoBroker.buildManifest().each { String key, String value -> + propertiesNode.appendNode(elementName("nebula_$key"), value) + } } }) } @@ -61,15 +68,4 @@ class MavenManifestPlugin implements Plugin { }) } } - - @CompileDynamic - private void appendManifest(XmlProvider xml, Map manifest) { - def propertiesNode = xml.asNode()?.properties - if (!propertiesNode) { - propertiesNode = xml.asNode().appendNode('properties') - } - manifest.each { String key, String value -> - propertiesNode.appendNode(elementName("nebula_$key"), value) - } - } } diff --git a/src/main/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPlugin.groovy index 327c921..560d94a 100644 --- a/src/main/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPlugin.groovy @@ -29,6 +29,7 @@ import org.gradle.api.publish.maven.MavenPublication * Removes from descriptor dependencies that are invalid: * 1) No version available */ +@CompileDynamic class MavenRemoveInvalidDependenciesPlugin implements Plugin { @Override void apply(Project project) { @@ -52,7 +53,14 @@ class MavenRemoveInvalidDependenciesPlugin implements Plugin { @Override void execute(XmlProvider xml) { - removeDependencies(xml) + def dependencies = xml.asNode()?.dependencies?.dependency + dependencies?.each { Node dep -> + String version = dep.version.text() + if (!version) { + dep.parent().remove(dep) + } + + } } }) } @@ -63,18 +71,6 @@ class MavenRemoveInvalidDependenciesPlugin implements Plugin { } }) } - - @CompileDynamic - private void removeDependencies(XmlProvider xml) { - def dependencies = xml.asNode()?.dependencies?.dependency - dependencies?.each { Node dep -> - String version = dep.version.text() - if (!version) { - dep.parent().remove(dep) - } - - } - } } diff --git a/src/main/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPlugin.groovy b/src/main/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPlugin.groovy index 8c7d5d8..19bafae 100644 --- a/src/main/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPlugin.groovy +++ b/src/main/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPlugin.groovy @@ -26,6 +26,7 @@ import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.MavenPublication +@CompileDynamic class MavenVerifyUnspecifiedVersionDependenciesPlugin implements Plugin { @Override void apply(Project project) { @@ -39,17 +40,22 @@ class MavenVerifyUnspecifiedVersionDependenciesPlugin implements Plugin @Override void execute(PublicationContainer publications) { publications.withType(MavenPublication) { MavenPublication publication -> - publication.pom(new Action() { - @Override void execute(MavenPom pom) { - pom.withXml(new Action() { - @Override void execute(XmlProvider xml) { - verifyVersionsInDependencies(xml) + def dependencies = xml.asNode()?.dependencies?.dependency + dependencies?.each { Node dep -> + String version = dep.version.text() + if(version == 'unspecified') { + String group = dep.groupId.text() + String name = dep.artifactId.text() + throw new GradleException("Dependency $group:$name has an invalid version: $version. This publication is invalid") + } + + } } }) } @@ -60,20 +66,6 @@ class MavenVerifyUnspecifiedVersionDependenciesPlugin implements Plugin } }) } - - @CompileDynamic - private void verifyVersionsInDependencies(XmlProvider xml) { - def dependencies = xml.asNode()?.dependencies?.dependency - dependencies?.each { Node dep -> - String version = dep.version.text() - if(version == 'unspecified') { - String group = dep.groupId.text() - String name = dep.artifactId.text() - throw new GradleException("Dependency $group:$name has an invalid version: $version. This publication is invalid") - } - - } - } } diff --git a/src/test/groovy/nebula/plugin/publishing/BaseIntegrationTestKitSpec.groovy b/src/test/groovy/nebula/plugin/publishing/BaseIntegrationTestKitSpec.groovy index 4e72ea4..dd975e5 100644 --- a/src/test/groovy/nebula/plugin/publishing/BaseIntegrationTestKitSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/BaseIntegrationTestKitSpec.groovy @@ -5,7 +5,7 @@ import nebula.test.IntegrationTestKitSpec abstract class BaseIntegrationTestKitSpec extends IntegrationTestKitSpec { def setup() { // Enable configuration cache :) - // new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent() + new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent() } void disableConfigurationCache() { diff --git a/src/test/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPluginIntegrationSpec.groovy index 3acb608..dd91061 100644 --- a/src/test/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/ivy/IvyBasePublishPluginIntegrationSpec.groovy @@ -43,6 +43,10 @@ class IvyBasePublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { } } } + + repositories { + mavenCentral() + } """.stripIndent() settingsFile << '''\ @@ -139,6 +143,7 @@ class IvyBasePublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { def 'creates a jar publication for scala projects'() { buildFile << '''\ apply plugin: 'scala' + '''.stripIndent() when: @@ -204,19 +209,13 @@ class IvyBasePublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { } def 'verify ivy.xml contains implementation and runtimeOnly dependencies'() { - def graph = new DependencyGraphBuilder().addModule('testjava:a:0.0.1').addModule('testjava:b:0.0.1').build() - File ivyrepo = new GradleDependencyGenerator(graph, "${projectDir}/testrepogen").generateTestIvyRepo() - buildFile << """\ apply plugin: 'java' - repositories { - ivy { url '${ivyrepo.absolutePath}' } - } dependencies { - implementation 'testjava:a:0.0.1' - runtimeOnly'testjava:b:0.0.1' + implementation 'com.google.guava:guava:19.0' + runtimeOnly 'org.apache.commons:commons-lang3:3.13.0' } """.stripIndent() @@ -224,8 +223,8 @@ class IvyBasePublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { runTasks('publishNebulaIvyPublicationToTestLocalRepository') then: - assertDependency('testjava', 'a', '0.0.1', 'runtime->default') - assertDependency('testjava', 'b', '0.0.1', 'runtime->default') + assertDependency('com.google.guava', 'guava', '19.0', 'runtime->default') + assertDependency('org.apache.commons', 'commons-lang3', '3.13.0', 'runtime->default') } boolean assertDependency(String org, String name, String rev, String conf = null) { diff --git a/src/test/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPluginIntegrationSpec.groovy index b5141b8..fdc8908 100644 --- a/src/test/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/ivy/IvyCompileOnlyPluginIntegrationSpec.groovy @@ -18,7 +18,9 @@ package nebula.plugin.publishing.ivy import nebula.plugin.publishing.BaseIntegrationTestKitSpec import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator +import spock.lang.Subject +@Subject(IvyCompileOnlyPlugin) class IvyCompileOnlyPluginIntegrationSpec extends BaseIntegrationTestKitSpec { File publishDir @@ -32,6 +34,10 @@ class IvyCompileOnlyPluginIntegrationSpec extends BaseIntegrationTestKitSpec { version = '0.1.0' group = 'test.nebula' + repositories { + mavenCentral() + } + publishing { repositories { ivy { @@ -51,18 +57,10 @@ class IvyCompileOnlyPluginIntegrationSpec extends BaseIntegrationTestKitSpec { def 'verify ivy contains compileOnly dependencies'() { keepFiles = true - def graph = new DependencyGraphBuilder().addModule('testjava:c:0.0.1').build() - File ivyrepo = new GradleDependencyGenerator(graph, "${projectDir}/testrepogen").generateTestIvyRepo() - buildFile << """\ apply plugin: 'java' - - repositories { - ivy { url '${ivyrepo.toURI().toURL()}' } - } - dependencies { - compileOnly 'testjava:c:0.0.1' + compileOnly 'com.google.guava:guava:19.0' } """.stripIndent() @@ -72,30 +70,23 @@ class IvyCompileOnlyPluginIntegrationSpec extends BaseIntegrationTestKitSpec { then: def root = new XmlSlurper().parseText(new File(publishDir, 'ivy-0.1.0.xml').text) def dependency = root.dependencies.dependency[0] - dependency.@org == 'testjava' - dependency.@name == 'c' - dependency.@rev == '0.0.1' + dependency.@org == 'com.google.guava' + dependency.@name == 'guava' + dependency.@rev == '19.0' dependency.@conf == 'provided' } def 'verify ivy contains compileOnly dependencies together with global excludes'() { keepFiles = true - def graph = new DependencyGraphBuilder().addModule('testjava:c:0.0.1').build() - File ivyrepo = new GradleDependencyGenerator(graph, "${projectDir}/testrepogen").generateTestIvyRepo() buildFile << """\ apply plugin: 'java' - - repositories { - ivy { url '${ivyrepo.toURI().toURL()}' } - } - configurations.all { exclude group: 'org.slf4j', module: 'slf4j-api' } dependencies { - compileOnly 'testjava:c:0.0.1' + compileOnly 'com.google.guava:guava:19.0' } """.stripIndent() @@ -105,9 +96,9 @@ class IvyCompileOnlyPluginIntegrationSpec extends BaseIntegrationTestKitSpec { then: def root = new XmlSlurper().parseText(new File(publishDir, 'ivy-0.1.0.xml').text) def dependency = root.dependencies.dependency[0] - dependency.@org == 'testjava' - dependency.@name == 'c' - dependency.@rev == '0.0.1' + dependency.@org == 'com.google.guava' + dependency.@name == 'guava' + dependency.@rev == '19.0' dependency.@conf == 'provided' } } diff --git a/src/test/groovy/nebula/plugin/publishing/ivy/IvyManifestPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/ivy/IvyManifestPluginIntegrationSpec.groovy index dde701f..4c78d72 100644 --- a/src/test/groovy/nebula/plugin/publishing/ivy/IvyManifestPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/ivy/IvyManifestPluginIntegrationSpec.groovy @@ -16,7 +16,9 @@ package nebula.plugin.publishing.ivy import nebula.plugin.publishing.BaseIntegrationTestKitSpec +import spock.lang.Subject +@Subject(IvyManifestPlugin) class IvyManifestPluginIntegrationSpec extends BaseIntegrationTestKitSpec { File publishDir diff --git a/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPluginSpec.groovy b/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPluginSpec.groovy index 29d955b..4c4692a 100644 --- a/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaPublishPluginSpec.groovy @@ -5,7 +5,7 @@ import org.gradle.testkit.runner.TaskOutcome class IvyNebulaPublishPluginSpec extends BaseIntegrationTestKitSpec { - def 'should successful publish with stable publishing feature flag'() { + def 'should successful publish'() { given: buildFile << """ plugins { diff --git a/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaShadowJarPublishPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaShadowJarPublishPluginIntegrationSpec.groovy index fdd5e31..0a5d8eb 100644 --- a/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaShadowJarPublishPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/ivy/IvyNebulaShadowJarPublishPluginIntegrationSpec.groovy @@ -16,8 +16,10 @@ package nebula.plugin.publishing.ivy import nebula.plugin.publishing.BaseIntegrationTestKitSpec +import spock.lang.Subject import spock.lang.Unroll +@Subject(IvyShadowPublishPlugin) class IvyNebulaShadowJarPublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { def setup() { keepFiles = true diff --git a/src/test/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPluginSpec.groovy b/src/test/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPluginSpec.groovy index da9adcf..fe10627 100644 --- a/src/test/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/ivy/IvyRemovePlatformDependenciesPluginSpec.groovy @@ -51,12 +51,15 @@ class IvyRemovePlatformDependenciesPluginSpec extends BaseIntegrationTestKitSpec apply plugin: 'java' repositories { - ${generator.ivyRepositoryBlock} mavenCentral() + ${generator.ivyRepositoryBlock} + maven { + url = 'https://repo.jenkins-ci.org/releases/' + } } dependencies { - implementation platform('com.github.sghill.jenkins:jenkins-bom:latest.release') + implementation platform('org.jenkins-ci.main:jenkins-bom:latest.release') implementation 'test.resolved:a:1.+' } """.stripIndent() @@ -87,6 +90,12 @@ class IvyRemovePlatformDependenciesPluginSpec extends BaseIntegrationTestKitSpec version = '0.1.0' group = 'test.nebula' + repositories { + mavenCentral() + maven { + url = 'https://repo.jenkins-ci.org/releases/' + } + } publishing { repositories { ivy { @@ -140,7 +149,7 @@ repositories { } dependencies { - implementation platform('com.github.sghill.jenkins:jenkins-bom:latest.release') + implementation platform('org.jenkins-ci.main:jenkins-bom:latest.release') implementation platform(project(":platform")) implementation 'test.resolved:a:1.+' } @@ -192,14 +201,16 @@ dependencies { buildFile << """\ apply plugin: 'java' - repositories { ${generator.ivyRepositoryBlock} mavenCentral() + maven { + url = 'https://repo.jenkins-ci.org/releases/' + } } dependencies { - implementation enforcedPlatform('com.github.sghill.jenkins:jenkins-bom:latest.release') + implementation enforcedPlatform('org.jenkins-ci.main:jenkins-bom:latest.release') implementation 'test.resolved:a:1.+' } @@ -254,10 +265,13 @@ dependencies { repositories { ${generator.ivyRepositoryBlock} mavenCentral() + maven { + url = 'https://repo.jenkins-ci.org/releases/' + } } dependencies { - implementation enforcedPlatform('com.github.sghill.jenkins:jenkins-bom:latest.release') + implementation enforcedPlatform('org.jenkins-ci.main:jenkins-bom:latest.release') implementation 'test.resolved:a:1.+' } @@ -312,10 +326,13 @@ dependencies { repositories { ${generator.ivyRepositoryBlock} mavenCentral() + maven { + url = 'https://repo.jenkins-ci.org/releases/' + } } dependencies { - implementation enforcedPlatform('com.github.sghill.jenkins:jenkins-bom:latest.release') + implementation enforcedPlatform('org.jenkins-ci.main:jenkins-bom:latest.release') implementation 'test.resolved:a:1.+' } diff --git a/src/test/groovy/nebula/plugin/publishing/ivy/IvyResolvedDependenciesPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/ivy/IvyResolvedDependenciesPluginIntegrationSpec.groovy index aa7c2cd..dbbd1ad 100644 --- a/src/test/groovy/nebula/plugin/publishing/ivy/IvyResolvedDependenciesPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/ivy/IvyResolvedDependenciesPluginIntegrationSpec.groovy @@ -19,7 +19,9 @@ import nebula.plugin.publishing.BaseIntegrationTestKitSpec import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator import nebula.test.dependencies.ModuleBuilder +import spock.lang.Subject +@Subject(IvyResolvedDependenciesPlugin) class IvyResolvedDependenciesPluginIntegrationSpec extends BaseIntegrationTestKitSpec { File publishDir diff --git a/src/test/groovy/nebula/plugin/publishing/maven/MavenBasePublishPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/maven/MavenBasePublishPluginIntegrationSpec.groovy index 2eb7ac9..ffe2150 100644 --- a/src/test/groovy/nebula/plugin/publishing/maven/MavenBasePublishPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/maven/MavenBasePublishPluginIntegrationSpec.groovy @@ -18,7 +18,9 @@ package nebula.plugin.publishing.maven import nebula.plugin.publishing.BaseIntegrationTestKitSpec import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator +import spock.lang.Subject +@Subject(MavenBasePublishPlugin) class MavenBasePublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { File publishDir @@ -32,6 +34,10 @@ class MavenBasePublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { version = '0.1.0' group = 'test.nebula' + repositories { + mavenCentral() + } + publishing { repositories { maven { diff --git a/src/test/groovy/nebula/plugin/publishing/maven/MavenDeveloperPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/maven/MavenDeveloperPluginIntegrationSpec.groovy index 0ef3d3e..a4d0394 100644 --- a/src/test/groovy/nebula/plugin/publishing/maven/MavenDeveloperPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/maven/MavenDeveloperPluginIntegrationSpec.groovy @@ -16,7 +16,9 @@ package nebula.plugin.publishing.maven import nebula.plugin.publishing.BaseIntegrationTestKitSpec +import spock.lang.Subject +@Subject(MavenDeveloperPlugin) class MavenDeveloperPluginIntegrationSpec extends BaseIntegrationTestKitSpec { def setup() { buildFile << """\ diff --git a/src/test/groovy/nebula/plugin/publishing/maven/MavenNebulaSpringBootPublishPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/maven/MavenNebulaSpringBootPublishPluginIntegrationSpec.groovy index fd6cc64..22f085f 100644 --- a/src/test/groovy/nebula/plugin/publishing/maven/MavenNebulaSpringBootPublishPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/maven/MavenNebulaSpringBootPublishPluginIntegrationSpec.groovy @@ -16,21 +16,26 @@ package nebula.plugin.publishing.maven import nebula.plugin.publishing.BaseIntegrationTestKitSpec +import nebula.plugin.publishing.publications.SpringBootJarPlugin +import spock.lang.Subject +@Subject(SpringBootJarPlugin) class MavenNebulaSpringBootPublishPluginIntegrationSpec extends BaseIntegrationTestKitSpec { def setup() { keepFiles = true // Because Spring Boot 2.x uses project.conventions System.setProperty('ignoreDeprecations', 'true') + // spring dependency management does not support config cache. More in https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/312 + disableConfigurationCache() buildFile << """\ plugins { id 'com.netflix.nebula.maven-publish' - id 'org.springframework.boot' version '2.7.11' - id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'org.springframework.boot' version '2.7.17' + id 'io.spring.dependency-management' version '1.1.4' id 'java' - id "com.netflix.nebula.info" version "12.1.3" - id "com.netflix.nebula.contacts" version "7.0.0" + id "com.netflix.nebula.info" version "12.1.6" + id "com.netflix.nebula.contacts" version "7.0.1" } contacts { @@ -101,7 +106,7 @@ public class DemoApplication { def spring = dependencies.find { it.artifactId == 'spring-boot-starter-web' } then: - spring.version == '2.7.11' + spring.version == '2.7.17' when: def jar = new File(projectDir, "build/libs/mavenpublishingtest-0.1.0.jar") diff --git a/src/test/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPluginSpec.groovy b/src/test/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPluginSpec.groovy index 08ffc24..ad364d9 100644 --- a/src/test/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPluginSpec.groovy @@ -3,7 +3,9 @@ package nebula.plugin.publishing.maven import nebula.plugin.publishing.BaseIntegrationTestKitSpec import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator +import spock.lang.Subject +@Subject(MavenRemoveInvalidDependenciesPlugin) class MavenRemoveInvalidDependenciesPluginSpec extends BaseIntegrationTestKitSpec { File publishDir diff --git a/src/test/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPluginSpec.groovy b/src/test/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPluginSpec.groovy index 6cdad0b..f573ba6 100644 --- a/src/test/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/maven/MavenVerifyUnspecifiedVersionDependenciesPluginSpec.groovy @@ -3,7 +3,9 @@ package nebula.plugin.publishing.maven import nebula.plugin.publishing.BaseIntegrationTestKitSpec import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator +import spock.lang.Subject +@Subject(MavenVerifyUnspecifiedVersionDependenciesPlugin) class MavenVerifyUnspecifiedVersionDependenciesPluginSpec extends BaseIntegrationTestKitSpec { File publishDir diff --git a/src/test/groovy/nebula/plugin/publishing/verification/PublishVerificationPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/publishing/verification/PublishVerificationPluginIntegrationSpec.groovy index 24dc698..e296832 100644 --- a/src/test/groovy/nebula/plugin/publishing/verification/PublishVerificationPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/publishing/verification/PublishVerificationPluginIntegrationSpec.groovy @@ -13,9 +13,10 @@ import nebula.test.dependencies.GradleDependencyGenerator import nebula.test.dependencies.ModuleBuilder import nebula.test.functional.ExecutionResult import netflix.nebula.dependency.recommender.DependencyRecommendationsPlugin -import org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin +import spock.lang.Ignore import spock.lang.IgnoreIf +@Ignore class PublishVerificationPluginIntegrationSpec extends IntegrationSpec { def setup() {