Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gantsign/kotlin-maven-plugin-tools

Metadata extractor for Maven plugins written in Kotlin.
https://github.com/gantsign/kotlin-maven-plugin-tools

kotlin maven maven-plugin

Last synced: 3 months ago
JSON representation

Metadata extractor for Maven plugins written in Kotlin.

Awesome Lists containing this project

README

        

# Kotlin Maven Plugin Tools

[![Release](https://github.com/gantsign/kotlin-maven-plugin-tools/workflows/Build/badge.svg)](https://github.com/gantsign/kotlin-maven-plugin-tools/actions?query=workflow%3ABuild)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.gantsign.maven.plugin-tools/kotlin-maven-plugin-tools/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.gantsign.maven.plugin-tools/kotlin-maven-plugin-tools)
[![codecov](https://codecov.io/gh/gantsign/kotlin-maven-plugin-tools/branch/main/graph/badge.svg)](https://codecov.io/gh/gantsign/kotlin-maven-plugin-tools)
[![Known Vulnerabilities](https://snyk.io/test/github/gantsign/kotlin-maven-plugin-tools/badge.svg)](https://snyk.io/test/github/gantsign/kotlin-maven-plugin-tools)

Maven plugin metadata extractor for plugins written in Kotlin.

**This project is still a little new, so please help by reporting any issues you find.**

## Maven plugin support for Kotlin

The [Java5 annotation metadata extractor](https://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.html)
partially works for Kotlin files. It's able to pull all the information from the
annotations; the problem is the descriptions, deprecation messages and since
version information, is still extracted from the JavaDoc, and this doesn't work
for Kotlin files; the generated web site and the command line help are far less
useful without descriptions.

This project provides a Kotlin metadata extractor using the Kotlin compiler to
give the same support for Kotlin files, as the Java5 annotation extractor does
for Java files (including support for descriptions and since version
information from KDoc, and deprecation messages from `@kotlin.Deprecated`).

## Writing a Maven Plugin in Kotlin

Writing a Maven plugin in Kotlin (using this extractor) is much the same as it
normally is in Java; you extend `org.apache.maven.plugin.AbstractMojo`, annotate
the class and properties, and add descriptions in API code comments. However as
Kotlin has nullability constraints in the type system, you need to declare
whether properties can be `null` or not; you can use `lateinit` for the non-null
properties.

It's important that the nullability of the properties matches the value of
the `required` attribute of the
`org.apache.maven.plugins.annotations.Parameter` annotation, or you may get
unfriendly errors at runtime.

```kotlin
package com.example

import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugins.annotations.Mojo
import org.apache.maven.plugins.annotations.Parameter

/**
* Example description.
*/
@Mojo(name = "example")
class ExampleMojo : AbstractMojo() {

/**
* Optional parameter description.
*/
@Deprecated("Example optional parameter deprecated message.")
@Parameter(name = "optionalParameter")
var optionalParameter: String? = null

/**
* Required parameter description.
*
* @since 1.1
*/
@Parameter(name = "requiredParameter", required = true)
lateinit var requiredParameter: String

override fun execute() {
// Perform plugin action here
}
}
```

Your POM will include the following:

```xml

4.0.0

com.example
example-maven-plugin
1.0.0-SNAPSHOT

maven-plugin


${maven.version}


1.7.10
1.8
1.8
3.6.3
UTF-8
UTF-8



org.apache.maven
maven-core
${maven.version}


org.apache.maven
maven-plugin-api
${maven.version}


org.jetbrains.kotlin
kotlin-stdlib-jdk8
${kotlin.version}


org.apache.maven.plugin-tools
maven-plugin-annotations
3.6.4
provided


org.jetbrains.kotlin
kotlin-test-junit
${kotlin.version}
test


src/main/kotlin
src/test/kotlin


org.apache.maven.plugins
maven-plugin-plugin
3.6.4



kotlin





com.github.gantsign.maven.plugin-tools
kotlin-maven-plugin-tools

@version@




default-descriptor
process-classes


help-goal

helpmojo





org.jetbrains.kotlin
kotlin-maven-plugin
${kotlin.version}

1.8



compile

compile

process-sources


test-compile

test-compile

test-compile




```

License
-------

This software is licensed under the terms in the file named "LICENSE" in the
root directory of this project. This project has dependencies that are under
different licenses.

Author Information
------------------

John Freeman

GantSign Ltd.
Company No. 06109112 (registered in England)