I've been attempting to expand my understanding of maven by teaching it to build clojure [1,2].
[1]: http://clojure.org [2]: http://clojure.googlecode.com/svn/trunk [3]: git://github.com/kevinoneill/clojure.git Clojure already has a maven build, but all it does is package up the build products left behind by a previously executed ant build. I'd like a solution that's "pure maven". That would fit best into my existing work-flow and build server. Consider this a first baby-step toward "clojure-compiler-maven-plugin", if you like. The "kernel" of clojure (runtime library, which includes the compiler) is written in Java. The rest is written in Clojure. It is possible to just compile the just the java and then package the clojure sources together with the class files. This will work, but it's slow to start up since the core clojure libraries must be compiled from source at loading. It's more efficient to use the clojure to compile the clojure sources ahead of time to class files. (This is essentially what the ant build does.) #!/bin/bash mvn clean # pom file included at end of message # this compiles the java part of clojure, and copies the clojure # sources to target/classes unchanged. mvn compile # this compiles the clojure sources, which have been copied to # target/classes in place. java -Dclojure.compile.path=$classes \ -cp target/classes clojure.lang.Compile \ clojure.core \ clojure.main \ clojure.set \ clojure.xml \ clojure.zip \ clojure.inspector # this packages it all up: clojure sources, class files from java, # class files from clojure. mvn package This is obviously a hack, and not "pure maven" by any stretch. How would an experienced maven user go about this? (1) Is there a way to embed imperative logic in the pom, perhaps with a fragment of ant, and get it to run at the correct stage during the build life cycle? (2) This problem would be "solved" if we had a clojure-compiler-maven-plugin to call upon, but of course if we wanted it to perform well, we'd want to make sure that the copy of clojure it used had itself been built with the clojure-compiler-maven-plugin. ;-) How would you, as a maven user, go about this? // ben ------------------------------------------ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- groupId: so as not to confuse this project with the real clojure --> <groupId>org.clojure.bpsm</groupId> <artifactId>clojure-lang</artifactId> <name>clojure-lang</name> <version>1.0-SNAPSHOT</version> <url>http://clojure.org/</url> <description>Clojure runtime library (and compiler).</description> <licenses> <license> <name>Eclipse Public License 1.0</name> <url>http://opensource.org/licenses/eclipse-1.0.php</url> <distribution>repo</distribution> </license> </licenses> <build> <!-- would be nice to use src/main/java as per maven convention --> <sourceDirectory>src/jvm</sourceDirectory> <resources> <resource> <!-- clojure sources are just 'resources', copied as is into the resulting jar --> <directory>src/clj</directory> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <!-- clojure requires at least java 1.5 --> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>clojure.main</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
