kaakaa Blog

この世は極楽 空にはとんぼ

共通のタスクをプロジェクト毎の設定値を利用して実行する

昨日の続き。

build.gradle

allprojects {
	configurations {
		svnant
	}
	
	ext {
		dep_repopath = new File("${project.rootDir}/../svn_repo/").canonicalPath
		dep_destpath = 'dep_project'
		depProjects = []
	}
	 
	dependencies {
		svnant fileTree(dir: "${project.rootDir}/lib_svnant", include: '**/*.jar')
	}

	task svnCheckout << {
		ant.taskdef(resource: 'org/tigris/subversion/svnant/svnantlib.xml', classpath: configurations.svnant.asPath)
	
		depProjects.each { def projectName ->
			def checkoutDest = "${project.rootDir}/${dep_destpath}/${projectName}"
			ant.svn(javahl: 'false', svnkit: 'true', failonerror: 'false') {
				ant.checkout(url: "file://${dep_repopath}/${projectName}", destpath: checkoutDest)
				ant.update(dir: checkoutDest)
			}
		}
	}
}

subprojects {
	apply plugin: 'java'
	
	repositories {
		mavenCentral()
	}
	
	dependencies {
	    compile 'org.slf4j:slf4j-api:1.7.5'
	    testCompile 'junit:junit:4.11'
	}
}

project(':App') {
	ext {
		depProjects = ["Stab"]
	}

	dependencies {
	    compile project(':dep_project/Stab')
	}

	compileJava.dependsOn svnCheckout
}

全プロジェクト共通のタスクsvnCheckoutでは、プロパティdepProjectsで指定されたプロジェクトをチェックアウトしてくる。

共通部分では

ext {
	dep_repopath = new File("${project.rootDir}/../svn_repo/").canonicalPath
	dep_destpath = 'dep_project'
	depProjects = []
}

のようにdepProjectsを空リストとして宣言しておき、Appプロジェクトの設定の方で

project(':App') {
	ext {
		depProjects = ["Stab"]
	}

	dependencies {
	    compile project(':dep_project/Stab')
	}

	compileJava.dependsOn svnCheckout
}

depProjectsに設定値を与えてあげると、共通のタスクをプロジェクト固有の設定値で実行することが出来る。