Skip to content

Instantly share code, notes, and snippets.

@gsitgithub
Created August 7, 2015 04:56
Show Gist options
  • Save gsitgithub/62e85cd74fe129f85e73 to your computer and use it in GitHub Desktop.
Save gsitgithub/62e85cd74fe129f85e73 to your computer and use it in GitHub Desktop.
/**
Copy compile dependencies to $webAppDirName/WEB-INF/lib
Creates a eclipse project with all dependencies that compiles classes into
$webAppDirName/WEB-INF/classes and test classes into /build/test-classes.
Requires: gradle 1.0rc2 or greater
We are using this gradle file:
apply from: 'path/webapp.gradle'
group = 'com.mycompany'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.0.1'
}
Then execute 'gradle idea' or 'gradle eclipse' to generate a project that can be deployed in IntelliJ Community Edition.
*/
import org.gradle.plugins.ide.eclipse.model.SourceFolder
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'eclipse'
// webinflib
if (!hasProperty('webAppDirName')) {
project.webAppDirName = 'src/main/webapp'
}
task 'cleanWebinflib' << {
ant.delete(dir: "$webAppDirName/WEB-INF/lib")
}
clean.dependsOn cleanWebinflib
task 'webinflib' << {
copy {
from configurations.runtime.files - configurations.providedCompile.files
into "$webAppDirName/WEB-INF/lib"
}
}
eclipseClasspath.dependsOn webinflib
tasks.idea.dependsOn webinflib
eclipse {
classpath {
defaultOutputDir = file("$webAppDirName/WEB-INF/classes")
file.whenMerged { cp ->
cp.entries.findAll { it instanceof SourceFolder && it.path.startsWith("src/test/") }*.output = "build/test-classes"
}
}
}
// workaround http://issues.gradle.org/browse/GRADLE-1984
eclipse.classpath.file.beforeMerged { classpath -> classpath.entries.clear() }
idea {
// see http://gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
module {
inheritOutputDirs = false
outputDir = file( (project.hasProperty('webAppDirName')? webAppDirName : 'war') + '/WEB-INF/classes')
testOutputDir = file('build/test-classes')
}
project {
ipr.withXml { provider ->
// Get root node.
def project = provider.asNode()
def encoding = project.component.find { it.@name == 'Encoding' }
if (encoding) {
// Change existing node.
encoding.@useUTFGuessing = true
encoding.@native2AsciiForPropertiesFiles = false
encoding.@defaultCharsetForPropertiesFiles = 'UTF-8'
encoding.appendNode 'file', [url: 'file://$PROJECT_DIR$', charset: 'UTF-8']
} else {
// Create new node with default values.
project.appendNode 'component', [name: 'Encoding', useUTFGuessing: true, native2AsciiForPropertiesFiles: false, defaultCharsetForPropertiesFiles: 'UTF-8']
}
}
}
}
war {
exclude 'WEB-INF/lib/**'
exclude 'WEB-INF/classes/**'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment