Maven clojure components

Maven components for using clojure in maven plugins

License

License

Categories

Categories

Clojure Languages Maven Build Tools
GroupId

GroupId

org.cloudhoist
ArtifactId

ArtifactId

clojure-maven
Last Version

Last Version

0.3.3
Release Date

Release Date

Type

Type

pom
Description

Description

Maven clojure components
Maven components for using clojure in maven plugins
Source Code Management

Source Code Management

https://github.com/pallet/clojure-maven

Download clojure-maven

Filename Size
clojure-maven-0.3.3.pom 3 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/org.cloudhoist/clojure-maven/ -->
<dependency>
    <groupId>org.cloudhoist</groupId>
    <artifactId>clojure-maven</artifactId>
    <version>0.3.3</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/org.cloudhoist/clojure-maven/
implementation 'org.cloudhoist:clojure-maven:0.3.3'
// https://jarcasting.com/artifacts/org.cloudhoist/clojure-maven/
implementation ("org.cloudhoist:clojure-maven:0.3.3")
'org.cloudhoist:clojure-maven:pom:0.3.3'
<dependency org="org.cloudhoist" name="clojure-maven" rev="0.3.3">
  <artifact name="clojure-maven" type="pom" />
</dependency>
@Grapes(
@Grab(group='org.cloudhoist', module='clojure-maven', version='0.3.3')
)
libraryDependencies += "org.cloudhoist" % "clojure-maven" % "0.3.3"
[org.cloudhoist/clojure-maven "0.3.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • mojo-annotations
  • mojo-descriptor-extractor
  • plexus-component-factory
  • plexus-clojure-compiler
  • plexus-clojurescript-compiler
  • mojo

clojure-maven

Maven components to allow the use of clojure when writing maven plugins.

Usage

clojure plugin

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.

    (ns example.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}" :required true :readonly true}}
       base-directory

       ^{Parameter
         {:defaultValue "${project.compileClasspathElements}"
          :required true :readonly true :description "Compile classpath"}}
       classpath-elements

       ^{Parameter
         {:defaultValue "${project.testClasspathElements}"
          :required true :readonly true}}
       test-classpath-elements

       ^{Parameter
         {:defaultValue "${project.build.outputDirectory}" :required true}}
       output-directory

       ^{:volatile-mutable true}
       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))

    (defn make-SimpleMojo
      "Function to provide a no argument constructor"
      []
      (SimpleMojo. nil nil nil nil nil (atom nil)))

For convenience, you may instead use the defmojo macro:

    (ns example.simple
      "Simple Mojo"
      (:use clojure.maven.mojo.defmojo
            clojure.maven.mojo.log))

    (defmojo SimpleMojo

      {:goal "simple"
       :requires-dependency-resolution "test" }

      ;; parameters
      [base-directory     {:expression "${basedir}" :required true :readonly true}

       classpath-elements {:required true :readonly true
                           :description "Compile classpath"
                           :defaultValue "${project.compileClasspathElements}" }

       test-classpath-elements {:required true :readonly true
                                :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.

pom.xml

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>

Example

See zi.

License

Licensed under EPL

org.cloudhoist

pallet

Versions

Version
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0