Maven components to allow the use of clojure when writing maven plugins.
To write a clojure plugin, you create a deftype, implement the Mojo interface,
and create a no-argument constructor function (which must be named
make-YourType).
Annotations are used to get values from the pom.
(nsexample.simple"Simple mojo"
(:import
java.io.File
[clojure.maven.annotations
Goal RequiresDependencyResolution Parameter Component]
org.apache.maven.plugin.ContextEnabled
org.apache.maven.plugin.Mojo
org.apache.maven.plugin.MojoExecutionException))
(deftype
^{Goal "simple"
RequiresDependencyResolution "test"}
SimpleMojo
[
^{Parameter
{:expression"${basedir}":requiredtrue:readonlytrue}}
base-directory
^{Parameter
{:defaultValue"${project.compileClasspathElements}":requiredtrue:readonlytrue:description"Compile classpath"}}
classpath-elements
^{Parameter
{:defaultValue"${project.testClasspathElements}":requiredtrue:readonlytrue}}
test-classpath-elements
^{Parameter
{:defaultValue"${project.build.outputDirectory}":requiredtrue}}
output-directory
^{:volatile-mutabletrue}
log
plugin-context
]
Mojo
(execute [_]
(.info log sourceDirectories))
(setLog [_ logger] (set! log logger))
(getLog [_] log)
ContextEnabled
(setPluginContext [_ context] (reset! plugin-context context))
(getPluginContext [_] @plugin-context))
(defnmake-SimpleMojo"Function to provide a no argument constructor"
[]
(SimpleMojo.nilnilnilnilnil (atomnil)))For convenience, you may instead use the defmojo macro:
(nsexample.simple"Simple Mojo"
(:use clojure.maven.mojo.defmojo
clojure.maven.mojo.log))
(defmojoSimpleMojo
{:goal"simple":requires-dependency-resolution"test" }
;; parameters
[base-directory {:expression"${basedir}":requiredtrue:readonlytrue}
classpath-elements {:requiredtrue:readonlytrue:description"Compile classpath":defaultValue"${project.compileClasspathElements}" }
test-classpath-elements {:requiredtrue:readonlytrue:defaultValue"${project.testClasspathElements}" } ]
;; Body that is executed when Mojo is run
(do
(info"Hi Maven World!")
(info (str"basedir is: " base-directory))))Note1: defmojo implicitly defines params 'log' and 'plugin-context' for you.
Note2: clojure.maven.mojo.log defines convenience functions debug, info, etc.
for you to send messages to Maven's log stream.
To write a plugin in clojure, your pom packaging should be set to maven-plugin.
<packaging>maven-plugin</packaging>To enable the mojo descriptor extractor, the maven-plugin plugin needs to be
configured.
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.6</version>
<dependencies>
<dependency>
<groupId>org.cloudhoist</groupId>
<artifactId>clojure-maven-mojo-descriptor-extractor</artifactId>
<version>0.3.3</version>
</dependency>
</dependencies>
</plugin>To write the mojo, you will need to make use of the annotations in
clojure-maven-mojo-annotations:
<dependency>
<groupId>org.cloudhoist</groupId>
<artifactId>clojure-maven-mojo-annotations</artifactId>
<version>0.3.3</version>
</dependency>And to be able to use the mojo, you need a dependency on
clojure-maven-plexus-component-factory:
<dependency>
<groupId>org.cloudhoist</groupId>
<artifactId>clojure-maven-plexus-component-factory</artifactId>
<version>0.3.3</version>
<scope>runtime</scope>
</dependency>To be able to find the artifacts, add the sonatype repository.
<repository>
<id>sonatype</id>
<url>http://oss.sonatype.org/content/repositories/releases</url>
</repository>See zi.
Licensed under EPL