Skip to content

Commit

Permalink
Provide way to configure plugin dependencies
Browse files Browse the repository at this point in the history
The MavenPluginDevelopmentExtension now provides a property
'dependencies' for controlling which dependencies should be added to the
plugin descriptor. The default value for this property is the
runtimeClasspath configuration.

Resolves #12
  • Loading branch information
britter committed Apr 12, 2020
1 parent 3c5a772 commit b0cb1e7
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 47 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,53 @@ dependencies {
}
```

## Controling plugin dependencies

By default all dependencies from the runtime classpath will in added to the dependencies blog of the generated plugin descriptor.
The can be changed by configuring the `dependencies` property on the `mavenPlugin` extension.
In the following examples only `org.apache.commons:commons-lang3:3.9` will be added as a dependency to the plugin descriptor:


### Gradle Groovy DSL

```groovy
plugins {
id 'de.benediktritter.maven-plugin-development' version '0.1.0'
}
configurations {
deps
}
dependencies {
deps "org.apache.commons:commons-lang3:3.9"
implementation "com.google.guava:guava:28.0-jre"
}
mavenPlugin {
dependencies = configurations.deps
}
```

### Gradle Kotlin DSL

```kotlin
plugins {
id("de.benediktritter.maven-plugin-development") version "0.1.0"
}

val deps by configurations.creating

dependencies {
deps("org.apache.commons:commons-lang3:3.9")
implementation("com.google.guava:guava:28.0-jre")
}

mavenPlugin {
dependencies.set(deps)
}
```

## Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.
Expand Down
6 changes: 6 additions & 0 deletions RELEASE_HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# 0.2.0 - TBA

## Breaking changes

* Class `..model.RuntimeDependencyDescriptor` has been removed.

## New Features

* Provide way to configure plugin dependencies
https://github.com/britter/maven-plugin-development/issues/12
* Define dedicated configuration for projects providing mojos
https://github.com/britter/maven-plugin-development/issues/11
* Add support for mojos from other projects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.benediktritter.maven.plugin.development

import org.gradle.api.artifacts.Configuration
import org.gradle.api.provider.Property
import org.gradle.api.tasks.SourceSet

Expand All @@ -40,4 +41,11 @@ interface MavenPluginDevelopmentExtension {
val goalPrefix: Property<String>

val generateHelpMojo: Property<Boolean>

/**
* The set of dependencies to add to the plugin descriptor.
*
* Defaults to the runtime classpath of this projects.
*/
val dependencies: Property<Configuration>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package de.benediktritter.maven.plugin.development

import de.benediktritter.maven.plugin.development.internal.DefaultMavenPluginDevelopmentExtension
import de.benediktritter.maven.plugin.development.model.MavenPluginDescriptor
import de.benediktritter.maven.plugin.development.model.RuntimeDependencyDescriptor
import de.benediktritter.maven.plugin.development.task.GenerateHelpMojoSourcesTask
import de.benediktritter.maven.plugin.development.task.GenerateMavenPluginDescriptorTask
import org.gradle.api.Plugin
Expand Down Expand Up @@ -53,6 +52,7 @@ class MavenPluginDevelopmentPlugin : Plugin<Project> {
extension.goalPrefix.orNull
)
})
runtimeDependencies.set(extension.dependencies)
}
// TODO declare help properties as input
val mojoConfiguration = createConfiguration()
Expand All @@ -72,17 +72,7 @@ class MavenPluginDevelopmentPlugin : Plugin<Project> {
extension.goalPrefix.orNull
)
})
runtimeDependencies.set(
project.provider {
project.configurations["runtimeClasspath"].resolvedConfiguration.resolvedArtifacts.map {
RuntimeDependencyDescriptor(
it.moduleVersion.id.group,
it.moduleVersion.id.name,
it.moduleVersion.id.version,
it.extension
)
}
})
runtimeDependencies.set(extension.dependencies)

dependsOn(extension.pluginSourceSet.map { it.output }, generateHelpMojoTask)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package de.benediktritter.maven.plugin.development.internal

import de.benediktritter.maven.plugin.development.MavenPluginDevelopmentExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.provider.Property
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
Expand Down Expand Up @@ -50,5 +51,8 @@ open class DefaultMavenPluginDevelopmentExtension @Inject constructor(project: P

override val generateHelpMojo: Property<Boolean> = project.objects.property<Boolean>()
.convention(false)

override val dependencies: Property<Configuration> = project.objects.property<Configuration>()
.convention(project.configurations["runtimeClasspath"])
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
package de.benediktritter.maven.plugin.development.task

import de.benediktritter.maven.plugin.development.model.MavenPluginDescriptor
import de.benediktritter.maven.plugin.development.model.RuntimeDependencyDescriptor
import org.apache.maven.plugin.descriptor.PluginDescriptor
import org.apache.maven.project.MavenProject
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest
import org.apache.maven.tools.plugin.PluginToolsRequest
import org.codehaus.plexus.component.repository.ComponentDependency
import org.gradle.api.DefaultTask
import org.gradle.api.provider.ListProperty
import org.gradle.api.artifacts.Configuration
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Nested

abstract class AbstractMavenPluginDevelopmentTask : DefaultTask() {

@get:Nested
abstract val pluginDescriptor: Property<MavenPluginDescriptor>

@get:Nested
abstract val runtimeDependencies: ListProperty<RuntimeDependencyDescriptor>
@get:Input
abstract val runtimeDependencies: Property<Configuration>

protected fun createPluginDescriptor(): PluginDescriptor {
val pluginDescriptor = pluginDescriptor.get()
Expand All @@ -51,12 +51,12 @@ abstract class AbstractMavenPluginDevelopmentTask : DefaultTask() {
}

private fun getComponentDependencies(): List<ComponentDependency> {
return runtimeDependencies.get().map { dependency ->
return runtimeDependencies.get().resolvedConfiguration.resolvedArtifacts.map { artifact ->
ComponentDependency().also {
it.groupId = dependency.groupId
it.artifactId = dependency.artifactId
it.version = dependency.version
it.type = dependency.type
it.groupId = artifact.moduleVersion.id.group
it.artifactId = artifact.moduleVersion.id.name
it.version = artifact.moduleVersion.id.version
it.type = artifact.extension
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,30 @@ class MavenPluginDevelopmentPluginFuncTest extends AbstractPluginFuncTest {
mojo.parameters.contains(new DescriptorFile.ParameterDeclaration("outputDirectory", File, false, true, "The output directory to put the file into."))
}

def "provides control over plugin dependencies"() {
given:
javaMojo()
buildFile << """
configurations {
deps
}
dependencies {
deps "org.apache.commons:commons-lang3:3.9"
implementation "com.google.guava:guava:28.0-jre"
}
mavenPlugin {
dependencies = configurations.deps
}
"""

when:
run(":generateMavenPluginDescriptor")

then:
pluginDescriptor.hasDependency('org.apache.commons:commons-lang3:3.9')
!pluginDescriptor.hasDependency('com.google.guava:guava:28.0-jre')
}

@Unroll
def "task is executed when #task lifecycle task is executed"() {
given:
Expand Down

0 comments on commit b0cb1e7

Please sign in to comment.