Skip to content

Instantly share code, notes, and snippets.

@tiqwab
Created April 19, 2016 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiqwab/81e4761300b6da56a6b93f4d74f306fd to your computer and use it in GitHub Desktop.
Save tiqwab/81e4761300b6da56a6b93f4d74f306fd to your computer and use it in GitHub Desktop.
subprojects {
apply plugin: 'eclipse'
apply plugin: 'java'
// 全ソースがUTF-8であることを指定する、
// この記述であればsourceSetが増えても対応可能。
def defaultEncoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = defaultEncoding
}
// コンパイル対象バージョンの指定
sourceCompatibility = 1.8
targetCompatibility = 1.8
// version指定
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
// 全てのprojectで設定される依存性
dependencies {
compile 'org.projectlombok:lombok:1.16.8'
testCompile 'junit:junit:4.12'
}
}
project(':module-core') {
}
project(':module-core-export') {
// 個々のprojectでのみ必要な依存性
// 他のprojectの依存性も設定可能であり、eclipseの.classpathファイルにも反映される。
dependencies {
compile project(':module-core')
}
}
project(':module-core-import') {
dependencies {
compile project(':module-core')
}
}
project(':module-export-foo') {
apply plugin: 'application'
mainClassName = 'org.tiqwab.example.gradle.multi.BatMainExport'
project.ext['scriptType'] = 'export'
dependencies {
compile project(':module-core-export')
compile 'org.apache.commons:commons-lang3:3.4'
}
}
project(':module-import-bar') {
apply plugin: 'application'
mainClassName = 'org.tiqwab.example.gradle.multi.BatMainImport'
project.ext['scriptType'] = 'import'
dependencies {
compile project(':module-core-import')
}
}
// buildScriptタスクで作成されるdirectoryを消去する。
task clean {
doLast {
delete 'build'
}
}
// カスタムbuildタスク
task buildScript << {
// build先のdirectory作成
// gradle.propertiesで定義しているdot表記のproperties取得は要注意
def scriptDir = rootProject.properties['build.dir']
def baseDir = rootProject.properties['base.dir']
copy {
from "${baseDir}"
into "${scriptDir}"
exclude '**/*.bat'
exclude '**/*.sh'
includeEmptyDirs = true
}
// 依存libraryと各modleのcopy
def libDir = rootProject.properties['build.lib.dir']
def deps = []
subprojects.each { p ->
p.configurations.compile.each { dep ->
if (!deps.contains(dep)) {
deps << dep
}
}
def archiveJarPath = p.jar.archivePath
if (!deps.contains(archiveJarPath)) {
deps << archiveJarPath
}
}
copy {
from files(deps)
into libDir
}
// 各moduleの実行用スクリプトファイルの作成
def baseBinDir = rootProject.properties['base.bin.dir']
def binDir = rootProject.properties['build.bin.dir']
def execLibDir = rootProject.properties['exec.lib.dir']
subprojects.each { p ->
if (p.plugins.hasPlugin('application')) {
def classPath = [p.jar.archivePath] + p.configurations.compile
copy {
from baseBinDir
into binDir
include "**/${p.ext.scriptType}.sh"
rename '.*\\.sh', p.name + '.sh'
expand(
mainClassName: p.mainClassName,
classPath: classPath.collect{x -> "${execLibDir}/${x.name}"}.join(':')
)
}
}
}
}
@tiqwab
Copy link
Author

tiqwab commented May 15, 2016

For set encoding of eclipse project

eclipseJdt << {
     File f = file('.settings/org.eclipse.core.resources.prefs')
    f.withPrintWriter('UTF-8') { writer ->
        writer.println('eclipse.preferences.version=1')
        writer.println('encoding/<project>=UTF-8')
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment