clojure-maven-plexus-component-factory

Plexus component factory for clojure components

License

License

Categories

Categories

Clojure Languages Maven Build Tools
GroupId

GroupId

org.cloudhoist
ArtifactId

ArtifactId

clojure-maven-plexus-component-factory
Last Version

Last Version

0.3.3
Release Date

Release Date

Type

Type

jar
Description

Description

clojure-maven-plexus-component-factory
Plexus component factory for clojure components

Download clojure-maven-plexus-component-factory

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
org.clojure : clojure jar 1.2.1

provided (3)

Group / Artifact Type Version
org.codehaus.plexus : plexus-utils jar 2.0.5
org.codehaus.plexus : plexus-container-default jar 1.0-alpha-9-stable-1
org.codehaus.plexus : plexus-classworlds jar 2.2.0

Project Modules

There are no modules declared in this project.

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