Skip to content

Instantly share code, notes, and snippets.

@uklance
Created June 30, 2016 14:34
Show Gist options
  • Save uklance/efa7537285ec9d165489598ec9c8e8bc to your computer and use it in GitHub Desktop.
Save uklance/efa7537285ec9d165489598ec9c8e8bc to your computer and use it in GitHub Desktop.
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
//mavenLocal()
maven {
//url "https://repo.grails.org/grails/core"
url uri('C:/workspace/offline/build/offline-repo')
}
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.7.4"
classpath "org.grails.plugins:hibernate4:5.0.3"
}
}
version "0.1"
group "offline"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"asset-pipeline"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
//mavenLocal()
maven {
//url "https://repo.grails.org/grails/core"
url uri('C:/workspace/offline/build/offline-repo')
}
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web:3.1.4"
runtime "org.grails.plugins:asset-pipeline"
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
task offline(type: OfflineMavenRepository) {
configurations = [configurations.testRuntime, buildscript.configurations.classpath]
}
class OfflineMavenRepository extends DefaultTask {
@Input
List<Configuration> configurations
@OutputDirectory
File repoDir = new File(project.buildDir, 'offline-repo')
@TaskAction
void build() {
for (Configuration configuration : configurations) {
copyJars(configuration)
copyPoms(configuration)
}
}
private void copyJars(Configuration configuration) {
configuration.resolvedConfiguration.resolvedArtifacts.each { artifact ->
def moduleVersionId = artifact.moduleVersion.id
File moduleDir = new File(repoDir, "${moduleVersionId.group}/${moduleVersionId.name}/${moduleVersionId.version}")
GFileUtils.mkdirs(moduleDir)
GFileUtils.copyFile(artifact.file, new File(moduleDir, artifact.file.name))
}
}
private void copyPoms(Configuration configuration) {
def componentIds = configuration.incoming.resolutionResult.allDependencies.collect { it.selected.id }
def result = project.dependencies.createArtifactResolutionQuery()
.forComponents(componentIds)
.withArtifacts(MavenModule, MavenPomArtifact)
.execute()
for(component in result.resolvedComponents) {
def componentId = component.id
if(componentId instanceof ModuleComponentIdentifier) {
File moduleDir = new File(repoDir, "${componentId.group}/${componentId.module}/${componentId.version}")
GFileUtils.mkdirs(moduleDir)
File pomFile = component.getArtifacts(MavenPomArtifact)[0].file
GFileUtils.copyFile(pomFile, new File(moduleDir, pomFile.name))
}
}
}
}
assets {
minifyJs = true
minifyCss = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment