0
votes

What's the best way to use a grails application as a dependency? With the grails maven publisher plugin, I can push wars, but I can't seem to access the class model properly from other applications. Ideally, I could bulid a skinny war or jar, as I just need some domain classes and interfaces for spring remoting.

What's the best way to use a grails application as a dependency?

1
Is your other application built using grails? - Gregg

1 Answers

1
votes

After many hours, I created this, via grails create-script MavenInstall:

includeTargets << grailsScript("_GrailsWar")

target(main: "Install the grails jar into the local maven repository") {
    depends createConfig
    depends jar, createConfig

    try {
        runMaven("mvn.sh")
    }
    catch (IOException e) {
        runMaven("mvn.bat")
    }
}

target(jar: "Build Grails classes jar") {
    depends compile
    ant.jar(basedir: "target/classes", destfile: "target/${metadata.'app.name'}-${metadata.'app.version'}.jar")
}

def runMaven(mavenCommand) {
    def command = [mavenCommand, "install:install-file", "-DgroupId=${config.grails.project.groupId}", "-DartifactId=${metadata.'app.name'}",
            "-Dpackaging=jar", "-Dversion=${metadata.'app.version'}",
            "-Dfile=target/${metadata.'app.name'}-${metadata.'app.version'}.jar", "-DgeneratePom=true"]

    println "Executing ${command.join(" ")}"
    def proc = command.execute()

    println proc.in.text
}

setDefaultTarget(main)

There you go. Your grails application as a jar of classes.