Skip to content

Commit ec7f6f2

Browse files
committed
Added Clojure example
1 parent b5e4cce commit ec7f6f2

File tree

21 files changed

+349
-15
lines changed

21 files changed

+349
-15
lines changed

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ A repository containing different java tutorials
4646
- [Streaming JSON validation](streaming-json-validation)
4747

4848
## Miscellaneous 🎭
49-
- [JVM Rainbow - Mixing Java, Kotlin, Scala and Groovy](jvm-rainbow)
49+
- [JVM Rainbow - Mixing Java, Kotlin, Scala, Clojure and Groovy](jvm-rainbow)
5050

5151
# Contributing
5252

jvm-rainbow/README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# 🌈 JVM Rainbow
2-
## Using Java, Scala, Kotlin and Groovy
2+
## Using Java, Scala, Kotlin, Clojure and Groovy
33

44
This projects demonstrates the possibility of writing and using multiple JVM languages in a single project and single root package with Maven. It serves to help others to easily configure their project if they need a subset or the whole configuration.
5-
This small project has been extracted from the following project: [hakky54/mutual-tls-ssl](https://github.com/Hakky54/mutual-tls-ssl) which contains example http client configuration and example http requests written in Java, Scala, Kotlin and Groovy.
5+
This small project has been extracted from the following project: [hakky54/mutual-tls-ssl](https://github.com/Hakky54/mutual-tls-ssl) which contains example http client configuration and example http requests written in Java, Scala, Kotlin, Clojure and Groovy.
66

77
On this page you can find the [dependency](#required-dependencies) and [compiler/plugin configuration](#compiler-configuration) however, the detailed project configuration can be found in the [pom](pom.xml) file which contains the exact dependency/plugin version and configuration for unit testing.
88
Unit tests are also present and integrated in the maven test phase. Run `mvn verify` to see it in action
@@ -13,6 +13,9 @@ Unit tests are also present and integrated in the maven test phase. Run `mvn ver
1313
<groupId>org.apache.maven.plugins</groupId>
1414
<artifactId>maven-compiler-plugin</artifactId>
1515
<version>${version.maven-compiler-plugin}</version>
16+
<configuration>
17+
<release>8</release>
18+
</configuration>
1619
<executions>
1720
<execution>
1821
<id>default-compile</id>
@@ -44,7 +47,7 @@ Unit tests are also present and integrated in the maven test phase. Run `mvn ver
4447
<artifactId>kotlin-maven-plugin</artifactId>
4548
<version>${version.kotlin}</version>
4649
<configuration>
47-
<jvmTarget>11</jvmTarget>
50+
<jvmTarget>1.8</jvmTarget>
4851
</configuration>
4952
<executions>
5053
<execution>
@@ -76,8 +79,13 @@ Unit tests are also present and integrated in the maven test phase. Run `mvn ver
7679
<groupId>net.alchim31.maven</groupId>
7780
<artifactId>scala-maven-plugin</artifactId>
7881
<version>${version.scala-maven-plugin}</version>
82+
<configuration>
83+
<source>1.8</source>
84+
<target>1.8</target>
85+
</configuration>
7986
<executions>
8087
<execution>
88+
<phase>generate-sources</phase>
8189
<goals>
8290
<goal>compile</goal>
8391
<goal>testCompile</goal>
@@ -86,6 +94,28 @@ Unit tests are also present and integrated in the maven test phase. Run `mvn ver
8694
</executions>
8795
</plugin>
8896

97+
<plugin>
98+
<groupId>com.theoryinpractise</groupId>
99+
<artifactId>clojure-maven-plugin</artifactId>
100+
<version>${version.clojure-maven-plugin}</version>
101+
<extensions>true</extensions>
102+
<configuration>
103+
<sourceDirectories>
104+
<sourceDirectory>src/main/java</sourceDirectory>
105+
</sourceDirectories>
106+
<temporaryOutputDirectory>true</temporaryOutputDirectory>
107+
</configuration>
108+
<executions>
109+
<execution>
110+
<id>compile-clojure</id>
111+
<phase>compile</phase>
112+
<goals>
113+
<goal>compile</goal>
114+
</goals>
115+
</execution>
116+
</executions>
117+
</plugin>
118+
89119
<plugin>
90120
<groupId>org.codehaus.gmavenplus</groupId>
91121
<artifactId>gmavenplus-plugin</artifactId>
@@ -170,4 +200,9 @@ Unit tests are also present and integrated in the maven test phase. Run `mvn ver
170200
<artifactId>groovy</artifactId>
171201
<version>${version.groovy}</version>
172202
</dependency>
203+
<dependency>
204+
<groupId>org.clojure</groupId>
205+
<artifactId>clojure</artifactId>
206+
<version>${version.clojure}</version>
207+
</dependency>
173208
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.github.hakky54</groupId>
8+
<artifactId>jvm-rainbow</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>jvm-rainbow-app</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.github.hakky54</groupId>
17+
<artifactId>jvm-rainbow-service</artifactId>
18+
<version>1.0.0-SNAPSHOT</version>
19+
</dependency>
20+
</dependencies>
21+
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>com.theoryinpractise</groupId>
26+
<artifactId>clojure-maven-plugin</artifactId>
27+
<version>1.9.3</version>
28+
<extensions>true</extensions>
29+
<configuration>
30+
<temporaryOutputDirectory>true</temporaryOutputDirectory>
31+
<script>src/main/java/nl/altindag/jvm/rainbow/app/ClojureApp.clj</script>
32+
</configuration>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
37+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(ns nl.altindag.jvm.rainbow.app.ClojureApp
2+
(:gen-class)
3+
(:require [nl.altindag.jvm.rainbow.service.ClojureService :as clojureService] )
4+
(:import
5+
[nl.altindag.jvm.rainbow.service JavaService]
6+
[nl.altindag.jvm.rainbow.service KotlinService]
7+
[nl.altindag.jvm.rainbow.service GroovyService]
8+
[nl.altindag.jvm.rainbow.service ScalaService]))
9+
10+
(defn -main
11+
[& args]
12+
(println (.hello (new JavaService))))
13+
(println (.hello (new ScalaService)))
14+
(println (.hello (new GroovyService)))
15+
(println (.hello (clojureService/reify-greetings-service)))
16+
(println (.hello (new KotlinService)))
17+
18+
(-main)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.altindag.jvm.rainbow.app
17+
18+
import clojure.java.api.Clojure
19+
import clojure.lang.IFn
20+
import nl.altindag.jvm.rainbow.service.GreetingsService
21+
import nl.altindag.jvm.rainbow.service.GroovyService
22+
import nl.altindag.jvm.rainbow.service.JavaService
23+
import nl.altindag.jvm.rainbow.service.KotlinService
24+
import nl.altindag.jvm.rainbow.service.ScalaService
25+
26+
static void main(String[] args) {
27+
println new JavaService().hello()
28+
println new GroovyService().hello()
29+
println new KotlinService().hello()
30+
println new ScalaService().hello()
31+
32+
// Below steps are required to call Clojure from Groovy
33+
IFn require = Clojure.var("clojure.core", "require")
34+
require.invoke(Clojure.read("nl.altindag.jvm.rainbow.service.ClojureService"))
35+
IFn greetingsFactory = Clojure.var("nl.altindag.jvm.rainbow.service.ClojureService", "reify-greetings-service")
36+
GreetingsService clojureService = (GreetingsService) greetingsFactory.invoke()
37+
println clojureService.hello()
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.altindag.jvm.rainbow.app;
17+
18+
import clojure.java.api.Clojure;
19+
import clojure.lang.IFn;
20+
import nl.altindag.jvm.rainbow.service.GreetingsService;
21+
import nl.altindag.jvm.rainbow.service.GroovyService;
22+
import nl.altindag.jvm.rainbow.service.JavaService;
23+
import nl.altindag.jvm.rainbow.service.KotlinService;
24+
import nl.altindag.jvm.rainbow.service.ScalaService;
25+
26+
public class JavaApp {
27+
28+
public static void main(String[] args) {
29+
System.out.println(new JavaService().hello());
30+
System.out.println(new KotlinService().hello());
31+
System.out.println(new ScalaService().hello());
32+
System.out.println(new GroovyService().hello());
33+
34+
// Below steps are required to call Clojure from Java
35+
IFn require = Clojure.var("clojure.core", "require");
36+
require.invoke(Clojure.read("nl.altindag.jvm.rainbow.service.ClojureService"));
37+
IFn greetingsFactory = Clojure.var("nl.altindag.jvm.rainbow.service.ClojureService", "reify-greetings-service");
38+
GreetingsService clojureService = (GreetingsService) greetingsFactory.invoke();
39+
System.out.println(clojureService.hello());
40+
}
41+
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.altindag.jvm.rainbow.app
17+
18+
import clojure.java.api.Clojure
19+
import nl.altindag.jvm.rainbow.service.GreetingsService
20+
import nl.altindag.jvm.rainbow.service.GroovyService
21+
import nl.altindag.jvm.rainbow.service.JavaService
22+
import nl.altindag.jvm.rainbow.service.KotlinService
23+
import nl.altindag.jvm.rainbow.service.ScalaService
24+
25+
const val clojureServiceNameSpace = "nl.altindag.jvm.rainbow.service.ClojureService"
26+
27+
fun main() {
28+
println(JavaService().hello())
29+
println(KotlinService().hello())
30+
println(ScalaService().hello())
31+
println(GroovyService().hello())
32+
33+
// Below steps are required to call Clojure from Kotlin
34+
val require = Clojure.`var`("clojure.core", "require")
35+
require.invoke(Clojure.read(clojureServiceNameSpace))
36+
val greetingsFactory = Clojure.`var`(clojureServiceNameSpace, "reify-greetings-service")
37+
val clojureService = greetingsFactory.invoke() as GreetingsService
38+
println(clojureService.hello())
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.altindag.jvm.rainbow.app
17+
18+
import clojure.java.api.Clojure
19+
import nl.altindag.jvm.rainbow.service._
20+
21+
object ScalaApp {
22+
23+
private val clojureServiceNameSpace: String = "nl.altindag.jvm.rainbow.service.ClojureService"
24+
25+
def main(args: Array[String]): Unit = {
26+
println(new JavaService().hello())
27+
println(new KotlinService().hello())
28+
println(new ScalaService().hello())
29+
println(new GroovyService().hello())
30+
31+
// Below steps are required to call Clojure from Scala
32+
val require = Clojure.`var`("clojure.core", "require")
33+
require.invoke(Clojure.read(clojureServiceNameSpace))
34+
val greetingsFactory = Clojure.`var`(clojureServiceNameSpace, "reify-greetings-service")
35+
val clojureService = greetingsFactory.invoke.asInstanceOf[GreetingsService]
36+
System.out.println(clojureService.hello)
37+
}
38+
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.github.hakky54</groupId>
8+
<artifactId>jvm-rainbow</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>jvm-rainbow-service</artifactId>
13+
14+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
;
2+
; Copyright 2022 Thunderberry.
3+
;
4+
; Licensed under the Apache License, Version 2.0 (the "License");
5+
; you may not use this file except in compliance with the License.
6+
; You may obtain a copy of the License at
7+
;
8+
; https://www.apache.org/licenses/LICENSE-2.0
9+
;
10+
; Unless required by applicable law or agreed to in writing, software
11+
; distributed under the License is distributed on an "AS IS" BASIS,
12+
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
; See the License for the specific language governing permissions and
14+
; limitations under the License.
15+
;
16+
17+
(ns nl.altindag.jvm.rainbow.service.ClojureService
18+
(:gen-class)
19+
(:import
20+
[nl.altindag.jvm.rainbow.service GreetingsService]))
21+
22+
(defn reify-greetings-service
23+
[]
24+
(reify
25+
GreetingsService
26+
(hello [this] (str "Greetings from Clojure!"))))

0 commit comments

Comments
 (0)