Hi guys, I’m trying to make an application with gradle and grails. My problem is that I would like to make the project available offline, but if I comment out the maven { url “https://repo.grails.org/grails/core” } line I get a build error, but if the line is left uncommented it works. I have a local maven repository and I believe everything is cached there already, so how could I make it work wothout the online repository?
There’s also the --offline flag at the command line to use the gradle cache
There’s also this gist which can store project dependencies on the local file system
Thanks, I have tried out your fix but I got a lot of error messages, which I have included
The error messages:
FAILURE: Build failed with an exception.
> * What went wrong:
> A problem occurred configuring root project 'offline'.
> > Could not resolve all dependencies for configuration ':runtime'.
> > Could not resolve org.springframework.boot:spring-boot-starter-logging:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.springframework.boot:spring-boot-autoconfigure:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.grails:grails-core:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.springframework.boot:spring-boot-starter-actuator:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.springframework.boot:spring-boot-starter-tomcat:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.grails:grails-dependencies:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.grails:grails-web-boot:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.grails.plugins:cache:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.grails.plugins:scaffolding:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.grails.plugins:hibernate4:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.hibernate:hibernate-ehcache:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve org.grails.plugins:asset-pipeline:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
> > Could not resolve com.h2database:h2:.
> Required by:
> offline:offline:0.1
> > Cannot change dependencies of configuration 'detachedConfiguration1' after it has been resolved.
So my problem is, that if I use
maven {
url “https://repo.grails.org/grails/core”
//url uri(‘C:/Programs/maven-repository/’)
}
the URL it works, but if I comment it out and try to use the local version I get a lot of errors, but the grails website works, even offline because I have it cached on the system.
Thank I have tried it out it really works if I use the --offline parameter, but the problem is that it is using the cache, but the project I am working on requires that I can put the libraries under configuration management, so I have to make sure that, the project doesn’t use the cache, only the available maven-repository (in my case under C:\Programs).
So is there a way I can make the project to run only from the local repository without the cache?
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?
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:
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?
Thank you, I really appreciate your help, but it still doesn’t work. I checked the files, and they are there, maybe the problem is that it is looking for the files at:
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 , 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.