Search code examples
grailsgroovynexus

Issues deploying grails plugin to Nexus


I have a grails project, configured to be a plugin, and what i want to do is push this into a local Nexus repository.

I have been able to do this using the grails release plugin, but when I then use the dependency my project using the dependency cant find the classes.

So I looking into the jar to see why and it looks like none of the Groovy code has been compiled, it looks like all the groovy file have just been packaged together instead of compiling the code first.

Any ideas what I am doing wrong?

Info about what I am doing:

Grails: 2.4.3

BuildConfig.groovy

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"

grails.project.repos.nexus.url = "http://xxxxx:8081/repository/maven-snapshots/"
grails.project.repos.default = "nexus"
grails.project.repos.nexus.username = "xxxx"
grails.project.repos.nexus.password = "xxxxx"

grails.project.fork = [
    // configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
    //  compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

    // configure settings for the test-app JVM, uses the daemon by default
    test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
    // configure settings for the run-app JVM
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the run-war JVM
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the Console UI JVM
    console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
    // inherit Grails' default dependencies

    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        grailsCentral()
        mavenLocal()
        mavenCentral()
    }
    dependencies {
       compile 'com.xxx:lsi-client:1.0-SNAPSHOT'
    }

    plugins {
        build ':release:3.0.1', {
            export = false
        }
    }
}

To create the artifact I run the following command

grails maven-deploy

I have also tried the following command

grails publish-plugin --repository=nexus

I have a standard directory structure for grails project. Not sure what other info to provide. Pulling my hair out at this point.

When I run a grails-compile that does the correct thing as expected and the groovy classes are compiled into the target/classes directory.


Solution

  • For those of you that are interested in the answer here, I eventually joined the Grails Slack community and someone there kindly answered my question:

    Grails 2 plugins just package up the source, whether a zip or jar, the classes wont be compiled. They are compiled by the application that uses the plugin

    Grails 3+ is different from what I understand, plugins are all jars and are compiled.

    Good to know but just another reason to upgrade away from Grails 2...

    EDIT: Found something else which has helped, if you need the domain classes in your grails 2 plugin compiled and packaged as a jar in your maven local repo then you can achieve this with the following command

    grails maven-install --binary
    

    Also ensure that your artifact type in your pom.xml is also set to jar (or left out as I think default artifact type is jar)

    <?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">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.company</groupId>
        <artifactId>ArtifactName</artifactId>
        <packaging>jar</packaging>
        <version>0.1</version>
    

    Hope this helps someone else out.