Hi,

Am 22.07.2009 um 20:46 schrieb Christopher Wilson:

Sorry if this is a bit OT, but has anyone created an ant or maven jar
task (maven: is 'goal' the correct term)? In the few jars that I've
created I've AOT compiled my .clj files and hand-created the jar file.
The way that I do this is compile to the default clojure "classes"
directory, I then pull the two sub directories (in my case usually a
'com/' and 'clojure/') out into the project root, leaving me with
something like this:

   project/
     com/
     clojure/
     clojure.jar

In the manifest I then specify the Main-Class as 'com.sencjw.project'
and the Class-Path as just '.' (dot). I've been unable to do it any
other way. Do others have a better method? Thanks!

I use a standard build.xml for all my prijects, which compiles
the clojure code, creates a compiled and a source jar and
handles dependencies via Ivy (optional).

The build.xml reads a local.properties file, which might specify
the position of the clojure.jar (then Ivy is *not* used) and
eg. a proxy. The version.properties stuff is still only experimental.
It is ripped off from clojure's build.xml, which does something
similar.

I attached a template, if you are interested. Search for
HERE to find the spots, which need to be changed.
(Ant gurus: How to reduce them?)

Sincerely
Meikel

<!--
 Copyright 2009 © Meikel Brandmeyer.
 All rights reserved.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to
 deal in the Software without restriction, including without limitation the
 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 sell copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN THE SOFTWARE.
 -->
<!--
 Project Name    – nomen est omen, eg. jazz
 Package Package – prefix for your project, eg. de.kotka
 Dir Prefix      – the corresponding namespace directory, eg. de/kotka
 -->
<project name="<!-- PROJECT NAME HERE -->" default="all"
    xmlns:ivy="antlib:org.apache.ivy.ant">

    <property name="ant.project.package" value="<!-- PACKAGE HERE -->"/>
    <property name="ant.project.dirprefix" value="<!-- DIR PREFIX HERE -->"/>

    <property name="src.dir" location="src"/>
    <property name="classes.dir" location="classes"/>
    <property name="build.dir" location="build"/>
    <property name="lib.dir" location="lib"/>

    <property name="jar.file" location="${build.dir}/${ant.project.name}.jar"/>
    <property name="srcjar.file"
        location="${build.dir}/${ant.project.name}-source.jar"/>

    <property name="version.file"
        location="${src.dir}/${ant.project.dirprefix}/${ant.project.name}.version.properties"/>

    <property name="ivy.install.version" value="2.1.0-rc1"/>
    <property name="ivy.jar.file" value="${lib.dir}/ivy.jar"/>

    <property file="local.properties"/>
    <property file="${version.file}"/>

    <target name="init" description="--> create build directories">
        <tstamp/>
        <mkdir dir="${classes.dir}"/>
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${lib.dir}"/>
    </target>

    <condition property="ivy.available">
        <available resource="org/apache/ivy/ant/antlib.xml"/>
    </condition>

    <condition property="ivy.disabled">
        <isset property="clojure.jar"/>
    </condition>

    <condition property="proxy.needed">
        <and>
            <isset property="proxy.host"/>
            <not><isset property="proxy.user"/></not>
        </and>
    </condition>

    <condition property="authproxy.needed">
        <and>
            <isset property="proxy.host"/>
            <isset property="proxy.user"/>
        </and>
    </condition>

    <condition property="ivy.needed">
        <and>
            <not><istrue value="${ivy.available}"/></not>
            <not><istrue value="${ivy.disabled}"/></not>
        </and>
    </condition>

    <target name="set-normal-proxy" if="proxy.needed"
        description="--> set the proxy if the user configured one">
        <setproxy proxyhost="proxy.host" proxyport="proxy.port"/>
    </target>

    <target name="set-auth-proxy" if="authproxy.needed"
        description="--> set the proxy if the user configured one">
        <setproxy proxyhost="proxy.host" proxyport="proxy.port"
            proxyuser="proxy.user" proxypassword="proxy.pass"/>
    </target>

    <target name="set-proxy" depends="set-normal-proxy,set-auth-proxy"
        description="--> set the proxy if the user configured one"/>

    <target name="download-ivy" depends="init,set-proxy" if="ivy.needed"
        description="--> download Ivy if necessary">
        <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar";
            dest="${ivy.jar.file}"
            usetimestamp="true"/>
    </target>

    <target name="install-ivy" depends="download-ivy" if="ivy.needed"
        description="--> install Ivy if necessary">
        <path id="ivy.lib.path">
            <fileset dir="${lib.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
            uri="antlib:org.apache.ivy.ant"
            classpathref="ivy.lib.path"/>
    </target>

    <target name="resolve" depends="install-ivy,init,set-proxy"
        unless="ivy.disabled"
        description="--> resolve dependencies with Ivy">
        <ivy:resolve />
        <ivy:retrieve />
    </target>

    <target name="aot" depends="resolve,init"
        description="--> AOT compile clojure sources">
        <java classname="clojure.lang.Compile" failonerror="true">
            <classpath>
                <path location="${classes.dir}"/>
                <path location="${src.dir}"/>
                <path location="${clojure.jar}"/>
                <path location="${clojure-contrib.jar}"/>
                <fileset dir="${lib.dir}" includes="**/*.jar"/>
            </classpath>
            <sysproperty key="clojure.compile.path" value="${classes.dir}"/>
            <!-- Reasonable default. Add/Change namespace definition HERE -->
            <arg value="${ant.project.package}.${ant.project.name}"/>
        </java>
    </target>

    <target name="artifacts" depends="aot"
        description="--> create source and artifact jars">
        <jar jarfile="${jar.file}">
            <path location="README.txt"/>
            <path location="LICENSE.txt"/>
            <fileset dir="${src.dir}"
                includes="${ant.project.dirprefix}/${ant.project.name}.version.properties"/>
            <fileset dir="${classes.dir}" includes="**/*"/>
            <manifest>
                <attribute name="Class-Path" value="."/>
            </manifest>
        </jar>
        <jar jarfile="${srcjar.file}">
            <path location="README.txt"/>
            <path location="LICENSE.txt"/>
            <fileset dir="${src.dir}" includes="**/*"/>
        </jar>
    </target>

    <target name="all" depends="artifacts"
        description="--> build the whole project"/>

    <target name="clean" description="--> clean generated files">
        <delete dir="${classes.dir}"/>
        <delete dir="${build.dir}"/>
    </target>

    <target name="clean-lib" description="--> clean library files">
        <delete dir="${lib.dir}"/>
    </target>

    <target name="clean-local" depends="install-ivy" unless="ivy.disabled"
        description="--> clean local repository files">
        <ivy:info />
        <delete dir="${ivy.local.default.root}/${ivy.organisation}/${ivy.module}"/>
    </target>

    <target name="clean-all" depends="clean-lib,clean"
        description="--> clean all project files"/>

    <target name="publish" depends="set-proxy"
        unless="${ant.project.name}.version.interim"
        description="--> publish artifacts in the shared repository">
        <ivy:info />
        <!-- I'm not sure how to the reduce repetition here. -->
        <ivy:publish
            resolver="shared"
            artifactspattern="${build.dir}/[artifact].[ext]"
            pubrevision="${<!-- PROJECT NAME HERE -->.version.major}.${<!-- PROJECT NAME HERE -->.version.minor}.${<!-- PROJECT NAME HERE -->.version.patchlevel}"
            update="true"
            status="release"/>
    </target>

    <target name="publish-local" depends="set-proxy"
        description="--> publish artifacts in the local repository">
        <tstamp>
            <format property="now" pattern="yyyyMMddHHmmss"/>
        </tstamp>
        <ivy:info />
        <ivy:publish
            resolver="local"
            artifactspattern="${build.dir}/[artifact].[ext]"
            pubrevision="${now}"
            pubdate="${now}"
            status="integration"
            forcedeliver="true"/>
    </target>

</project>
<ivy-module version="2.0">

    <info organisation="${ant.project.package}" module="${ant.project.name}"
        status="integration"/>

    <configurations>
        <conf name="source"/>
        <conf name="compiled"/>
        <conf name="default" extends="source,compiled"/>
    </configurations>

    <publications>
        <artifact name="${ant.project.name}" type="jar" conf="compiled"/>
        <artifact name="${ant.project.name}-source" type="jar" conf="source"/>
    </publications>

    <dependencies>
        <dependency org="org.clojure" name="clojure" rev="1.0.0" conf="*->@"/>
        <dependency org="org.clojure.contrib" name="def" rev="919" conf="*->@"/>
    </dependencies>

</ivy-module>
<ivysettings>

    <!-- Load the standard Ivy settings. Which just extend them for Clojure. -->
    <include url="${ivy.default.settings.dir}/ivysettings.xml"/>

    <!-- Include the Kotka ivyrep for Clojure and Contrib -->
    <include url="http://kotka.de/ivy/ivysettings.xml"/>

</ivysettings>

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to