1

I have a grails 2.5.3 app that uses Plugins and dependencies from maven. Now I'd like to use a Nexus server setup inside the company as a proxy for all the dependencies my app uses. However, I've never used Nexus before so I'm a bit confused as to how things would work.

I generated a POM.xml for my grails app using grails create-pom com.mycompany. The generated pom has the following artifactId

<groupId>com.mycompany</groupId>
<artifactId>myproj</artifactId>
<packaging>grails-app</packaging>
<version>1.0.0.R1</version>

Then I added the following to the POM.xml

  <distributionManagement>
    <repository>
      <id>nexus</id>
      <name>Nexus Repo</name>
      <url>https://companynextus/content/repositories/myproj</url>
    </repository>
  </distributionManagement>

Then I run mvn deploy

Now I can see my entire WAR file and POM at https://companynextus/content/repositories/myproj/com/mycompany/myproj/1.0.0.R1/

At this point I just change my BuildConfig.groovy from:

repositories {
    inherits true // Whether to inherit repository definitions from plugins

    grailsPlugins()
    grailsHome()
    mavenLocal()
    grailsCentral()
    mavenCentral()
}

To:

repositories {
    inherits true // Whether to inherit repository definitions from plugins

    grailsPlugins()
    grailsHome()
    grailsRepo "https://companynextus/content/repositories/myproj/com/mycompany/myproj/1.0.0.R1"
    mavenRepo "https://companynextus/content/repositories/myproj/com/mycompany/myproj/1.0.0.R1"
}

But I get error while doing grails prod war

Resolve error obtaining dependencies: Could not find artifact org.grails.plugins:tomcat:zip:8.0.33 in https://companynextus/content/repositories/myproj/com/mycompany/myproj/1.0.0.R1(https://companynextus/content/repositories/myproj/com/mycompany/myproj/1.0.0.R1) (Use --stacktrace to see the full trace)

Anthony
  • 33,838
  • 42
  • 169
  • 278
  • The title on this question is a bit odd, you are technically still using Maven, just using Nexus to proxy or host artifacts. – DarthHater Mar 26 '17 at 03:07

2 Answers2

1

We created a nexus repository group (http://nexushost/content/groups/repo), that caches all external maven repos (maven central, grails repos), and our internal releases repo too.

As for deployment, we have one repo for snapshots (http://nexushost/content/repositories/snapshots), and one repo for releases (http://nexushost/content/repositories/releases/).

This is an excerpt of our BuildConfig with grails 2.5.1. It should not be very different with your version:

def env = System.getenv() + new HashMap(System.properties)

grails {
    project {
        repos {
            SNAPSHOTS {
                url = "http://nexushost/content/repositories/snapshots"
                username = env.NEXUS_DEPLOY
                password = env.NEXUS_DEPLOY_PASS
            }
            RELEASES {
                url = "http://nexushost/content/repositories/releases/"
                username = env.NEXUS_DEPLOY
                password = env.NEXUS_DEPLOY_PASS
            }
        }
    }
}


grails.project.dependency.resolver = "maven" 
grails.project.dependency.resolution = {
    inherits("global") {
    }
    repositories {
        inherits true

        mavenLocal()
        mavenRepo('http://nexushost/content/groups/repo') {
            auth(
                    username: env.NEXUS_BUILD,
                    password: env.NEXUS_BUILD_PASS
            )
        }
        mavenRepo('http://nexushost/content/repositories/snapshots') {
            auth(
                    username: env.NEXUS_BUILD,
                    password: env.NEXUS_BUILD_PASS
            )
            updatePolicy 'always'
        }
    }

//....
}
Luis Muñiz
  • 4,649
  • 1
  • 27
  • 43
0

When you do mvn deploy command it's upload your project as a jar to the nexus repository but not upload each dependency separately, if you want to download and use the project dependencies from the nexus you need to upload the dependencies to the nexus too.

for more information about how to upload 3rd party jars to a repository like nexus https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html

If you use nexus 2 you can also do this from the ui.

Ron Badur
  • 1,873
  • 2
  • 15
  • 34