# Offline maven build

**URL:** <https://discuss.gradle.org/t/offline-maven-build/18277>\
**Category:** Help/Discuss\
**Created:** [June 29, 2016, 8:31am UTC](https://discuss.gradle.org/t/offline-maven-build/18277 "2016-06-29T08:31:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 29, 2016, 8:31am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/1 "2016-06-29T08:31:12Z")

</div>

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](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?

Thanks.

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 29, 2016, 9:49am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/2 "2016-06-29T09:49:56Z")

</div>

Do you have `mavenLocal()` configured?

```gradle
repositories {
   mavenLocal()
}

```

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 29, 2016, 9:51am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/3 "2016-06-29T09:51:38Z")

</div>

Yes I, have that line, but should I do something else as well?  
and I have C:/Programs/maven-repository in my settings.xml

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 29, 2016, 9:55am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/4 "2016-06-29T09:55:24Z")

</div>

Perhaps you need

```gradle
maven {
   url uri('C:/Programs/maven-repository')
}

```

There’s also the `--offline` flag at the command line to use the gradle cache  
There’s also [this gist](https://gist.github.com/bmuschko/e4e04abca105c397145e) which can store project dependencies on the local file system

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 29, 2016, 11:23am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/5 "2016-06-29T11:23:42Z")

</div>

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.
```

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 29, 2016, 11:49am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/6 "2016-06-29T11:49:00Z")

</div>

So my problem is, that if I use  
maven {  
url “[https://repo.grails.org/grails/core](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.

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 29, 2016, 12:07pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/7 "2016-06-29T12:07:11Z")

</div>

Have you tried

1. Running a normal build (to prep gradle’s cache)
2. Running a second build passing `--offline` at command line?

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 29, 2016, 2:11pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/8 "2016-06-29T14:11:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 29, 2016, 2:53pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/9 "2016-06-29T14:53:58Z")

</div>

You could use [this gist](https://gist.github.com/bmuschko/e4e04abca105c397145e) to backup your dependencies and then reference them via

```gradle
maven {
   url uri('c:/path/to/offline/dependencies')
}

```

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 30, 2016, 9:30am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/10 "2016-06-30T09:30:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 30, 2016, 11:46am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/11 "2016-06-30T11:46:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 30, 2016, 11:57am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/12 "2016-06-30T11:57:07Z")

</div>

I have uploaded the build.gradle [gist](https://gist.github.com/szakitom/36677a8d7ac77253174b344b2353bbd0)  
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
```

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 30, 2016, 12:11pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/14 "2016-06-30T12:11:47Z")

</div>

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:

```gradle
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

```gradle
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

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

```

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 30, 2016, 12:42pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/15 "2016-06-30T12:42:30Z")

</div>

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’)  
> }

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 30, 2016, 2:10pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/16 "2016-06-30T14:10:59Z")

</div>

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

```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

```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

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

```

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 30, 2016, 2:23pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/17 "2016-06-30T14:23:10Z")

</div>

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](https://gist.github.com/szakitom/36677a8d7ac77253174b344b2353bbd0)

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 30, 2016, 2:35pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/18 "2016-06-30T14:35:10Z")

</div>

> <https://gist.github.com/uklance/efa7537285ec9d165489598ec9c8e8bc>

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [June 30, 2016, 3:01pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/19 "2016-06-30T15:01:31Z")

</div>

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:

> 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

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [June 30, 2016, 3:43pm UTC](https://discuss.gradle.org/t/offline-maven-build/18277/20 "2016-06-30T15:43:05Z")

</div>

> 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]`

---

<div class="post-metadata">

**Author:** ![Szaki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szaki/32/5320_2.png) [@Szaki](https://discuss.gradle.org/u/Szaki)\
**Post date:** [July 1, 2016, 7:01am UTC](https://discuss.gradle.org/t/offline-maven-build/18277/21 "2016-07-01T07:01:49Z")

</div>

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.

[Next page](https://discuss.gradle.org/t/offline-maven-build/18277.md?page=2)
