Offline maven build

Yes, I have tried the gist, but it doesn’t copy everything because when I try to run it, I get errors saying that I don’t have a specific files at the path. So could it be that the gist doesn’t backup all the dependecies?

Please post the errors and relevant snippet from build.gradle, perhaps @bmuschko can help?

I have uploaded the build.gradle gist
Maybe the problem is that I didn’t include all the necessary dependencies into the gradle script.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'offline'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not find org.grails:grails-gradle-plugin:3.1.4.
     Searched in the following locations:
         file:/C:/workspace/offline/build/offline-repo/org/grails/grails-gradle-plugin/3.1.4/grails-gradle-plugin-3.1.4.pom
         file:/C:/workspace/offline/build/offline-repo/org/grails/grails-gradle-plugin/3.1.4/grails-gradle-plugin-3.1.4.jar
     Required by:
         :offline:unspecified
   > Could not find com.bertramlabs.plugins:asset-pipeline-gradle:2.7.4.
     Searched in the following locations:
         file:/C:/workspace/offline/build/offline-repo/com/bertramlabs/plugins/asset-pipeline-gradle/2.7.4/asset-pipeline-gradle-2.7.4.pom
         file:/C:/workspace/offline/build/offline-repo/com/bertramlabs/plugins/asset-pipeline-gradle/2.7.4/asset-pipeline-gradle-2.7.4.jar
     Required by:
         :offline:unspecified
   > Could not find org.grails.plugins:hibernate4:5.0.3.
     Searched in the following locations:
         file:/C:/workspace/offline/build/offline-repo/org/grails/plugins/hibernate4/5.0.3/hibernate4-5.0.3.pom
         file:/C:/workspace/offline/build/offline-repo/org/grails/plugins/hibernate4/5.0.3/hibernate4-5.0.3.jar
     Required by:
         :offline:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Ah… looks like you need to take a copy of the buildscript classpath configuration too.
Note that the OfflineMavenRepository accepts a configurationName parameter and looks it up via project.configurations.getByName(…). You’ll need to tweak it to accept a Configuration object instead of a string. Then you could do:

task exportRuntime(type: OfflineMavenRepository) {
   configuration = configurations.runtime
   repoDir = file('/path/to/repo')
}
task exportBulidscriptClasspath(type: OfflineMavenRepository) {
   configuration = buildscript.configurations.classpath
   repoDir = file('/path/to/repo')
}

Or perhaps

task exportBoth(type: OfflineMavenRepository) {
   configurations = [buildscript.configurations.classpath, configurations.runtime]
   repoDir = file('/path/to/repo')
}

Note: You’ll also need to declare the file path in your buildscript {} block when working offline

buildscript {
    repositories {
        maven { 
           url uri('c:/path/to/offline/dependencies')
        }
    }
}

Thanks, with the two export tasks it finally downloaded the core libraries, but it still can’t find the libs.
I have this in my buildscript: where offline-repo is the directory where the previous tasks downloaded the libraries. Should I give a different path to it?

buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
maven {
url uri(‘C:/workspace/offline/build/offline-repo’)
}

Are using the new or old syntax to declare org.grails:grails-gradle-plugin:3.1.4?

If you are using the “new” plugin syntax, you will have to add the following to settings.gradle

pluginRepositories {
  maven {
    url uri('C:/workspace/offline/build/offline-repo')
  }
}

If you are using the “old” plugins syntax you will need to add the following to build.gradle

buildscript {
   repositories {
      maven {
         url uri('C:/workspace/offline/build/offline-repo')
      }
   }
}

In both cases, you’ll also need a repository declaration for the normal dependencies

repositories {
   maven {
      url uri('C:/workspace/offline/build/offline-repo')
   }
}

I am using classpath “org.grails:grails-gradle-plugin:$grailsVersion” and I don’t have a settings.gradle file
https://gist.github.com/szakitom/36677a8d7ac77253174b344b2353bbd0

Thank you, I really appreciate your help, but it still doesn’t work. :frowning: I checked the files, and they are there, maybe the problem is that it is looking for the files at:

C:/workspace/offline/build/offline-repo/org/grails/grails-gradle-plugin/3.1.4/grails-gradle-plugin-3.1.4.pom

but they are actually at:

C:/workspace/offline/build/offline-repo/org.grails/grails-gradle-plugin\3.1.4/grails-gradle-plugin-3.1.4.pom

I don’t really know if it could be the problem or not.

Also if I enable the online repositories, gradle says

configurations = [configurations.testRuntime, buildscript.configurations.classpath]

line is problematic: Cannot get property ‘testRuntime’ on null object

but they are actually at: C:/workspace/offline/build/offline-repo/org.grails/grails-gradle-plugin\3.1.4/grails-gradle-plugin-3.1.4.pom

Looks like you’ll need to tweak the copyJars and copyPoms methods to replace dots with slashes in the group

eg change:

File moduleDir = new File(repoDir, "${moduleVersionId.group}/...")
to
File moduleDir = new File(repoDir, "${moduleVersionId.group.replace('.', '/')}/...")

Also if I enable the online repositories, gradle says
configurations = [configurations.testRuntime, buildscript.configurations.classpath]
line is problematic: Cannot get property ‘testRuntime’ on null object

Ah, that’s because the configurations task parameter is overriding project.configurations… try this instead:
configurations = [project.configurations.testRuntime, buildscript.configurations.classpath]

It is starting to look good :smiley: , but unfortunately I still get an error.

What went wrong:
Could not add entry ‘:offline’ to cache taskArtifacts.bin (C:\workspace\offline.gradle\2.9\taskArtifacts\taskArtifacts.bin).
> Unable to store task input properties. Property ‘configurations’ with value ‘[configuration ‘:testRuntime’, configuration ‘:classpath’]’ cannot be serialized.

I’m surprised a List of Configuration can’t be used as a task input. To get it working you could remove the @Input annotation from the task. Obviously up-to-date checking won’t work if you do this

eg:

@Input <-- remove this
List<Configuration> configurations

This possibly requires a jira to make the Configuration serializable… or maybe it would work with a newer version of gradle.

Possibly related to GRADLE-1784

Yes, now the offline task runs without any error, but if I comment out the url “https://repo.grails.org/grails/core” lines and try to use the local versions, I still get errors if I try to run the bootRun task. It looks like it still needs other files. To name a few: grails-bom, slf4j-1.7.10 (this is actually in the location but with different version).

I’m not familiar with the dependency-management-plugin but I’m guessing that there’s another configuration (or more) that need to be saved offline.

Try this:

task offline(type: OfflineMavenRepository) {
   def allConfigs = []
   allConfigs.addAll(project.configurations)
   allConfigs.addAll(buildscript.configurations)
   configurations = allConfigs
}

Still says it needs a lot of dependencies, which are not at the local folders.

As I said, I don’t know how the dependency management plugin works. Try creating another configuration with the missing dependencies so it’s backed up.

configurations {
   temp
}
dependencies {
   temp "org.grails:grails-bom:$grailsVersion"
}

Ok thanks, I’m gonna start to work on the missing dependencies and gonna report back, it that is gonna work.

Obviously that’s a bit of a hack. The proper solution is to source the missing dependencies from the dependency management plugin model somehow

So at last I have succeeded!
If anyone is interested I have used Nexus on my local computer, and set it up, so it would download everything into a specific folder. After that I was able to use this build.gradle (gist).
Also I had to save the gradle-2.9-bin.zip file and set it up in C:/path/project/gradle/wrapper/gradle-wrapper.properties like this:

distributionUrl=file:///C:/path/to/gradle-2.9-bin.zip