On Mar 26, 2010, at 5:35 AM, David Powell wrote:


I often want to add a custom task to a build, just as an example, I
might want to call a Java method in my code after it has built which
will generate a property file to be included in the distribution.

If this was just a make file or some sort batch file, then that would
just be an extra line in the build file.

In ant, yeah, it would be padded out with lots of XML, but it would
still be the addition of a fairly simple ant task.

In leiningen, it seems that I can create a leiningen/*.clj file with a
clojure function in it which will call my task.

In Maven, it seems that I have to go through this procedure?

http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

Is it really that complicated?


No. :-)

If you're looking to simply run a function after the build, if you're using maven, then you can either use the exec plugin (which can invoke any command line you like, or start up java with any options you want -- including all of your build and/or test dependencies, or not).

If you're looking to run a clojure script, clojure-maven-plugin has a 'run' goal that is a thin wrapper around the exec plugin's functionality. Thus, here's a chunk our of one of our pom.xml files that runs a script during the compile phase to generate a file we include in our .war file (we have others that run in other phases, such as to prep and tear down databases around functional tests, etc):

<execution>
    <id>generate-design-doc-json</id>
    <phase>compile</phase>
    <goals>
        <goal>run</goal>
    </goals>
    <configuration>
<script>${basedir}/src/main/clojure/com/snowtide/couchdb.clj</ script>
        <args>assemble-ddoc-json</args>
<clojureOptions>-Ddb.dir=databases -Ddb.assembly.target=$ {project.build.directory}/classes/</clojureOptions>
    </configuration>
</execution>

Certainly, this is not something that requires creating a new plugin -- just re-using the entry points that are there already.

... creating a Java class, annotating it with metadata, creating an
XML manifest file for it, packaging it in a jar file, installing it in
the local maven repository, referring to it from the project's pom.

Now, it *would* be nice, when it's really called for, to be able to create a maven plugin using clojure. The API is just a pile of interfaces, so it's fundamentally the same as implementing any other Java API. As for having to package it -- if you're using maven, that's trivial. ;-) (And a good thing to do regardless, so as to, again, promote reuse.)

Cheers,

- Chas

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or 
reply to this email with the words "REMOVE ME" as the subject.

Reply via email to