gradleclojureclojure-java-interop

how to run the clojure main from gradle application plugin


I've main clojure file -

(ns main.main
  (:gen-class))

(defn -main
      "I don't do a whole lot ... yet."
      [& args]
      (println "Hello, World!"))

I've build.gradle file -

plugins {
    id 'dev.clojurephant.clojure' version '0.7.0-alpha.1'
    id 'application'
}

group 'org.example'
version '0.0.1-SNAPSHOT'
repositories {
    maven {
        name = 'Clojars'
        url = 'https://repo.clojars.org'
    }
    mavenCentral()
}


dependencies {
    implementation 'org.clojure:clojure:1.11.1'

    testRuntimeOnly 'org.ajoberstar:jovial:0.3.0'

    devImplementation 'org.clojure:tools.namespace:1.3.0'
    
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
}

tasks.withType(Test) {
    useJUnitPlatform()
}

application {
    mainClassName("main.main")
}

Now I tried to run the gradle application using command gradle run and encountered below error -

Error: Could not find or load main class main.main

Caused by: java.lang.ClassNotFoundException: main.main

I tried some more application configuration but didn't work -


application {
    mainClass = "clojure.main"
    mainModule = "main.main"
}

what is the correct value of mainClass and mainModule.


Solution

  • Finally got it working. Missed the below config -

    clojure {
      builds {
        main {
          aotAll()
        }
      }
    }