Skip to content

Commit

Permalink
fix for dependencies not defined in pom
Browse files Browse the repository at this point in the history
changed how release work by publishing a software component (which contains the proper dependencies) + other artifacts (like javadoc and sources)
  • Loading branch information
ypujante committed Apr 30, 2021
1 parent a0360ea commit f32a40e
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 42 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ Check the `repositories.gradle` file that comes with this project for examples.
----------------------------
This plugin does the following (by default):

- creates a `releaseMaster` configuration which extends `archives`
- creates an empty `releaseMaster` configuration
- creates `javadocJar`, `groovydocJar` and `sourcesJar` tasks (depending on the kind of artifacts built)
- creates a `release` task which automatically publishes all the artifacts that are part of the `releaseMaster` configuration using a publication named `release` in a repository named `release`
- creates a `release` task which automatically publishes the `java` software component as well as all the artifacts
that are part of the `releaseMaster` configuration using a publication named `release` in a repository named `release`

This plugin is highly configurable:

- you can change the software component (`release.releaseComponent`)
- you can change the configurations (`release.releaseConfigurations`, `release.sourcesConfigurations`, `release.javadocConfigurations`, `release.groovydocConfigurations`)
- you can change the name of the task, repository or publication (all defaulting to `release`)
- you can disable the creation of the task entirely by setting `release.repositoryName` (or `release.publicationName`) to `null`
- you can invoke `release.createConfigurationPublicationTask(...)` to create your own task(s) to publish a particular configuration in a particular combination of publication/repository (useful after disabling the main task generation)
- you can invoke `release.task(...)` to create your own task(s) to publish a particular component and/or
configuration artifacts in a particular combination of publication/repository (useful after disabling
the main task generation)

This plugin exports the `releaseType` concept.

Expand Down
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
3.0.2 (2021/04/30)
------------------
* Fix for dependencies not included in pom: instead of publishing artifacts, publish a software component (+ other artifacts like javadoc and sources)

3.0.1 (2021/04/27)
------------------
* Fix when both javadoc and groovydoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class BuildInfo
String buildDurationString
def buildTasks
def buildProperties
def releasedComponent
def releasedArtifacts = Collections.synchronizedCollection([])
def publishedArtifacts = Collections.synchronizedCollection([])

Expand Down Expand Up @@ -96,6 +97,10 @@ public class BuildInfo
addArtifacts(project, configuration, releasedArtifacts)
}

void addReleasedComponent(def component) {
releasedComponent = component
}

private static void addArtifacts(Project project, Configuration configuration, def artifacts)
{
configuration.allArtifacts.all { PublishArtifact artifact ->
Expand Down Expand Up @@ -172,6 +177,9 @@ public class BuildInfo
if(buildTasks)
map.buildTasks = buildTasks

if(releasedComponent)
map.releasedComponent = releasedComponent

if(releasedArtifacts)
map.releasedArtifacts = releasedArtifacts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,16 @@ class CmdlinePlugin implements Plugin<Project>
from root
include pattern
compression = convention.compression
destinationDir = convention.packageFile.parentFile
archiveName = convention.packageFile.name
destinationDirectory = convention.packageFile.parentFile
archiveFileName = convention.packageFile.name
}

packageTask.doLast {
logger."${convention.cmdlineLogLevel}"("Created package [${convention.packageFile}]")
}

project.tasks.findByName(ReleasePlugin.RELEASE_MASTER_TASK_NAME)?.dependsOn(packageTask)

project.task([type: SingleArtifactTask, dependsOn: packageTask],
"package-assemble-artifact") {
artifactFile = convention.packageFile
Expand All @@ -235,7 +237,7 @@ class CmdlinePlugin implements Plugin<Project>
extension: convention.packageExtension,
configurations: convention.artifactConfigurations
]
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ import org.pongasoft.gradle.utils.Utils
* the 'releaseMaster' configuration or to a new configuration and make 'releaseMaster' extends
* from it.
*
* By convention ({@link ReleasePluginExtension#releaseConfigurations}) 'releaseMaster' extends
* from 'archives'.
*
* @author [email protected] */
class ReleasePlugin implements Plugin<Project>
{
public static final String RELEASE_MASTER_CONFIGURATION = 'releaseMaster'
public static final String RELEASE_MASTER_TASK_NAME = 'releaseMaster'

Project project

Expand All @@ -62,6 +60,9 @@ class ReleasePlugin implements Plugin<Project>
// creating releaseMaster configuration
Configuration releaseMasterConfiguration = findOrAddConfiguration(project, RELEASE_MASTER_CONFIGURATION)

// Create the task so that it is available in other plugins
project.tasks.register(RELEASE_MASTER_TASK_NAME)

/**
* Needs to be executed after the build script has been evaluated
*/
Expand All @@ -75,18 +76,20 @@ class ReleasePlugin implements Plugin<Project>
// 2. Add sources and docs
addSourcesAndDocs(extension)

// 3. Create releaseMaster task
// 3. Populate releaseMaster task
if(extension.publicationName && extension.repositoryName) {
Task releaseMasterTask =
extension.createConfigurationPublicationTask(releaseMasterConfiguration.name,
"releaseMaster",
extension.publicationName,
extension.repositoryName)
Task releaseMasterTask = extension.task(RELEASE_MASTER_TASK_NAME,
extension.publicationName,
extension.repositoryName,
extension.releaseComponent,
releaseMasterConfiguration.name)

if(releaseMasterTask) {
// 4. add the artifacts that were just released to the build info
releaseMasterTask.doLast {
buildInfo.addReleasedArtifacts(project, releaseMasterConfiguration)
if(extension.releaseComponent)
buildInfo.addReleasedComponent(extension.releaseComponent)
}

// 6. create the "release" convenient task
Expand Down Expand Up @@ -223,7 +226,8 @@ class ReleasePluginExtension
_project = project
}

def releaseConfigurations = ['archives'] as Set
def releaseComponent = 'java'
def releaseConfigurations = [] as Set
def sourcesConfigurations = [sources: []]
def javadocConfigurations = [javadoc: ['docs']]
def groovydocConfigurations = [groovydoc: ['docs']]
Expand All @@ -233,37 +237,53 @@ class ReleasePluginExtension
def publicationName = "release"

/**
* Creates a task with the provided name that will publish all artifacts defined by the provided configuration
* in the publication defined by the combination `publicationName`/`repositoryName`
* Registers (or reuse if exists) a task with the provided name. The (optional) component is added to the
* publication. The artifacts from the (optional) configuration are also added to the publication. The task
* is a shortcut to invoking the <code>publishXXXPublicationToYYYRepository</code> with a more manageable name
* (provided as argument to this call)
*
* @return the task or `null` if the configuration, publication or repository does not exist */
Task createConfigurationPublicationTask(String configurationName,
String taskName,
String publicationName,
String repositoryName) {

def configuration = _project.configurations.findByName(configurationName)
if(configuration == null) {
_project.logger.warn("[${_project.name}]: Could not find a configuration named [${configurationName}]")
return null
}
* @return the task or <code>null</code> if the configuration, component, publication or repository does not exist */
Task task(String taskName,
String publicationName,
String repositoryName,
String componentName = null,
String configurationName = null) {

def publication = _project.publishing.publications.findByName(publicationName)

// add all the artifacts from the configuration to the publication
if(publication) {
configuration.allArtifacts.each { artifact ->
if(artifact instanceof PublishArtifactImpl)
artifact.addToPublication(publication)
else
publication.artifact(artifact)
// add the main software components
if(componentName) {
def component = _project.components.findByName(componentName)
if(component) {
publication.from(component)
} else {
_project.logger.warn("[${_project.name}]: Could not find a component named [${componentName}]")
return null
}
}

// add other artifacts
if(configurationName) {
def configuration = _project.configurations.findByName(configurationName)
if (configuration == null) {
_project.logger.warn("[${_project.name}]: Could not find a configuration named [${configurationName}]")
return null
}

configuration.allArtifacts.each { artifact ->
if (artifact instanceof PublishArtifactImpl)
artifact.addToPublication(publication)
else
publication.artifact(artifact)
}
}
}

def repository = _project.publishing.repositories.findByName(repositoryName)

if(repository != null && publication != null) {
Task task = _project.tasks.register(taskName).get()
Task task = _project.tasks.findByName(taskName) ?: _project.tasks.register(taskName).get()
task.dependsOn("publish${publication.name.capitalize()}PublicationTo${repository.name.capitalize()}Repository")
return task
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import org.gradle.api.publish.plugins.PublishingPlugin
import org.pongasoft.gradle.utils.Utils

/**
* The purpose of this plugin is to apply the `signing` plugin and automatically:
* The purpose of this plugin is to apply the <code>signing</code> plugin and automatically:
*
* - populate the necessary properties by looking at argument on command line/env/userConfig/spec
* - add releaseMaster to the signed artifact (which adds a signReleaseMaster task) if
* `org.pongasoft.release` is used
* <code>org.pongasoft.release</code> is used
*/
class SigningPlugin implements Plugin<Project> {
private Project project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import org.pongasoft.gradle.core.ReleaseType
import org.pongasoft.gradle.utils.Utils

/**
* This plugin adds the `sonatype` extension to easily configure deployment to maven central.
* This plugin adds the <code>sonatype</code> extension to easily configure deployment to maven central.
*
* - populate the credentials by looking at argument on command line/env/userConfig/spec
* - use snapshots vs non snapshots urls
* - use `legacy` or `s01` repositories
* - use <code>legacy</code> or <code>s01</code> repositories
*/
class SonatypePublishingPlugin implements Plugin<Project> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Utils
}

/**
* @return `true` if the version is a snapshot version defined by `-SNAPSHOT` at the end */
* @return <code>true</code> if the version is a snapshot version defined by <code>-SNAPSHOT</code> at the end */
static boolean isSnapshotVersion(Project project) {
return project.version.endsWith('-SNAPSHOT')
}
Expand Down
3 changes: 3 additions & 0 deletions org.pongasoft.test-2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ apply plugin: org.pongasoft.gradle.plugins.ExternalPublishingPlugin
apply plugin: org.pongasoft.gradle.plugins.ReleasePlugin
apply plugin: org.pongasoft.gradle.plugins.SigningPlugin

release {
releaseComponent = null
}
2 changes: 1 addition & 1 deletion project-spec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
spec = [
name: 'gradle-plugins',
group: 'org.pongasoft',
version: '3.0.1',
version: '3.0.2',

versions: [
jdk: '8'
Expand Down

0 comments on commit f32a40e

Please sign in to comment.