Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjhargrave/add-maven-descriptor
Gradle Plugin to add maven descriptors when jars are built
https://github.com/bjhargrave/add-maven-descriptor
gradle maven plugin
Last synced: 27 days ago
JSON representation
Gradle Plugin to add maven descriptors when jars are built
- Host: GitHub
- URL: https://github.com/bjhargrave/add-maven-descriptor
- Owner: bjhargrave
- License: apache-2.0
- Created: 2022-07-11T19:10:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-13T11:41:15.000Z (about 2 months ago)
- Last Synced: 2024-09-14T01:32:57.864Z (about 2 months ago)
- Topics: gradle, maven, plugin
- Language: Groovy
- Homepage:
- Size: 550 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Add Maven Descriptor Gradle Plugin
When Maven builds a jar, by default the [Maven Archiver][1] includes the Maven descriptor information.
This is the pom.xml file at `META-INF/maven/${groupId}/${artifactId}/pom.xml` and the pom.properties file at `META-INF/maven/${groupId}/${artifactId}/pom.properties`.These resources are useful to have in jars when they are standing alone and disconnected from a repository.
Gradle's `Jar` task type does not include Maven descriptor information in built jars.
So this plugin was created to add the Maven descriptor information to built jars.## Configuring the plugin
The simplest way to use the plugin is to apply to your project.
```groovy
plugins {
id "dev.hargrave.addmavendescriptor" version "1.1.0"
}
```The `addmavendescriptor` plugin will apply the `maven-publish` plugin if it is not already applied.
The `maven-publish` plugin is used as the Maven descriptor information source.
A `MavenPublication` must be configured to define the Maven descriptor information which includes the `groupId` and `artifactId`.```groovy
publishing {
publications {
maven(MavenPublication) {
pom {
// Configure pom elements
}
}
}
}
```If no `MavenPublication` is defined, then the `addmavendescriptor` plugin does nothing.
So it is safe to apply to a project which does not define a `MavenPublication`.When only a single `MavenPublication` is defined, the `addmavendescriptor` plugin will automatically use it to obtain the Maven descriptor information and the pom file generator task defined by the `maven-publish` plugin when the `MavenPublication` is defined.
The `addmavendescriptor` plugin will define a pom properties file generator task for the `MavenPublication` and also configure all the `Jar` tasks to include the generated pom file and the generated pom properties file.If multiple `MavenPublication`s are defined, then you will need to tell the `addmavendescriptor` plugin which one to use for the Maven descriptor information.
This can be done at the project level and/or at the `Jar` task level.
The `addmavendescriptor` plugin adds an `addMavenDescriptor` extension to the project and to each `Jar` task.
So you can configure the name of the `MavenPublication` to use:```groovy
addMavenDescriptor {
publicationName = "maven"
}
```The configuration at the project level is used by all the `Jar` tasks unless you set the `publicationName` in the `Jar` task.
```groovy
tasks.named("jar") {
addMavenDescriptor {
publicationName = "maven"
}
}
```Finally, if you have a `Jar` task, or project, in which you don't want Maven descriptor, you can set `publicationName` to `null` to disable adding the maven descriptor.
```groovy
tasks.named("jar") {
addMavenDescriptor {
publicationName = null
}
}
```## Gradle Version
This plugin requires at least Gradle 6.1 for Java 8 to Java 15,
at least Gradle 7.0 for Java 16,
at least Gradle 7.3 for Java 17,
at least Gradle 7.5 for Java 18,
at least Gradle 7.6 for Java 19,
and at least Gradle 8.1 for Java 20.[1]: https://maven.apache.org/shared/maven-archiver/index.html