Clojure and maven

I had started about learning clojure and though the REPL interpreter seems to be the standard way of starting learning, I wanted to do it in a more Test driven method using maven. So I created a source and test directory and went about writing a simple learn.clj and a simple testlearn.clj. Took some time to figure things out and make the tests work Here is the directory structure


 (Learn.clj dir structure \NetBeans2\ClojureLearn2\src\main\clojure\my\clojure\learn.clj)


(ns my.clojure.learn
 (:gen-class))


(defn main  [args]
  (println  "A red apple tree" )
   (println (def x(str "Hello " args "!")) )
   x
 )


(defn add [x y]
    (+ x y)
)


( defn workingwithlist []
  (println "In the function workingwithlist")
  (def listx (list 1 (add 1 1) 3 4  ))
   (doseq [item listx]
   (println item))
     listx
  )

 (TestLern.clj dir structure \NetBeans2\ClojureLearn2\src\test\clojure\my\clojure\Testlearn.clj)



(ns my.clojure.Testlearn
(:use my.clojure.learn)
(:use clojure.test)
      (:gen-class)
 )
(deftest test-add
  ; equals is easy what about not equal to
  (is(not= 5 (add 1 2)))
  )
(deftest test-add2
  ; equals is easy what about not equal to
  (is(= 3 (add 1 2)))
  )


(deftest test-helloworld
  
  (is(= "Hello World!"(main "World")))
 )


(deftest test-lists
  (list? (workingwithlist))
  )

 And here is the pom.xml dir ( \ClojureLearn2\pom.xml) 

<?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">
<properties>
    <clojure.version>1.1.0</clojure.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>org.enclojure</groupId>
<artifactId>sample</artifactId>
<version>0.0.1</version>
<name>ClojureLearn2</name>
<description>ClojureLearn2</description>
<build>
    <sourceDirectory>src/main/clojure</sourceDirectory>
    <testSourceDirectory>src/test/clojure</testSourceDirectory>
    <resources>
        <resource>
            <directory>src/main/clojure</directory>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/clojure</directory>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <groupId>com.theoryinpractise</groupId>
            <artifactId>clojure-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
                <sourceDirectories>
                    <sourceDirectory>src/main/clojure</sourceDirectory>
                </sourceDirectories>
                <clojureOptions>-Xmx1G</clojureOptions>
            </configuration>
            <executions>
                <execution>
                    <id>compile-clojure</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-clojure</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>central</id>
        <url>http://repo1.maven.org/maven2</url>
    </repository>
    <repository>
        <id>clojure-releases</id>
        <url>http://build.clojure.org/releases</url>
    </repository>
    <repository>
        <id>incanter</id>
        <url>http://repo.incanter.org</url>
    </repository>
    <repository>
        <id>clojure-snapshots</id>
        <url>http://build.clojure.org/snapshots</url>
    </repository>
    <repository>
        <id>clojars</id>
        <url>http://clojars.org/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.clojure</groupId>
        <artifactId>clojure</artifactId>
        <version>${clojure.version}</version>
    </dependency>
    <dependency>
        <groupId>org.clojure</groupId>
        <artifactId>clojure-contrib</artifactId>
        <version>${clojure.version}</version>
    </dependency>
    <dependency>
        <groupId>swank-clojure</groupId>
        <artifactId>swank-clojure</artifactId>
        <version>1.1.0-SNAPSHOT</version>
        <exclusions>
            <exclusion>
                <groupId>org.clojure</groupId>
                <artifactId>clojure</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.clojure</groupId>
                <artifactId>clojure-contrib</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
</project>

Comments

Popular posts from this blog

Long running Java process resource consumption monitoring , leak detection and GC tuning

Best practises - Selenium WebDriver/ Java

CORBA - C++ Client (ACE TAO) Java Server (JacORB) A simple example