Version Catalogã¨ã¯
Gralde 7.0~å°å
¥ããããä¾åé¢ä¿ããã©ã°ã¤ã³ãéç´ç®¡çããããã®è¨å®æ¹æ³ã
å
¬å¼ï¼Sharing dependency versions between projects
åä¸ããã¸ã§ã¯ãã®å ´åãbuild.gradleã1ãã¡ã¤ã«ã§å®çµãããã¨ãå¤ãã®ã§ããã¾ãè¯ããæããããªããã
ãã«ãããã¸ã§ã¯ãã®å ´åãåãä¾åé¢ä¿ãä½åãæ¸ãå¿
è¦ããªããªãã®ã§ãå°å
¥ã®ã¡ãªãããæããããã
使ç¨æ¹æ³
以ä¸ã®build.gradleã Version Catalogã使ç¨ãããã®ã«ä¿®æ£ããªããã使ç¨æ¹æ³ã説æããã
Gradle Wrapper Version ï¼8.2.1
plugins { id 'java' id 'org.springframework.boot' version '2.7.15' id 'io.spring.dependency-management' version '1.0.15.RELEASE' } group = 'com.example' version = '1.0.0' java { sourceCompatibility = '17' } repositories { mavenCentral() } dependencies { // Spring implementation 'org.springframework.boot:spring-boot-starter' developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' // Apache Commons Lang3 implementation 'org.apache.commons:commons-lang3:3.12.0' // JUnit testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' } tasks.named('test') { useJUnitPlatform() }
libs.versions.tomlãã¡ã¤ã«ã®ä½æ
ä¾åé¢ä¿ãä¸å
管çãããã¡ã¤ã«ãä½æããã
ã«ã¼ãããã¸ã§ã¯ãã®ãgradleããã£ã¬ã¯ããªã®ç´ä¸ã«ãlibs.versions.tomlããä½æããã
å®ç¾©ã®è¿½å
ä½æãããlibs.versions.tomlãã«ä»¥ä¸ã®å®ç¾©ã追å ããã
[versions] [libraries] [plugins]
versions
ãã¼ã¸ã§ã³Noãå¤æ°ã«å
¥ãã¦ç®¡çããéã«è¨è¿°ããã
libraries
ä¾åé¢ä¿ã管çããéã«è¨è¿°ããã
plugins
ãã©ã°ã¤ã³ã管çããéã«è¨è¿°ããã
ä¾åé¢ä¿ã®å®ç¾©ãè¨è¿°ããï¼libs.versions.tomlï¼
ãlibs.versions.tomlãã®ãlibrariesãã«ä¾åé¢ä¿ã®å®ç¾©ã追å ããã以ä¸ã¯Apache Commons Lang3ã®å®ç¾©ã追å ããä¾ã§ããã
ãã®æãä¾åé¢ä¿ã«å¯¾ãã¦å½åãè¡ãããã±ããã±ã¼ã¹ï¼ãã¤ãã³åºåãï¼ã§è¨è¿°ããã
[versions] [libraries] commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = "3.12.0" } [plugins]
ãã¼ã¸ã§ã³Noããversionsãã«å¥å®ç¾©åãããã¨ãã§ããã以ä¸ã¯Junitã®å®ç¾©ã追å ããä¾ã§ããã
ãã®å ´åãä¾åé¢ä¿ã®å®ç¾©ã®ãã¼ã¸ã§ã³ã®æå®ã®ãã¼ããversion.refãã¨ãªããå¤ã«ã¯ãversionsãã«å®ç¾©ããå¤æ°åãæå®ããã
[versions] junitVersion = 5.9.1 [libraries] commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = "3.12.0" } junit = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junitVersion" } [plugins]
ä¾åé¢ä¿ã®å®ç¾©ãä¿®æ£ããï¼build.gradleï¼
ä¾åé¢ä¿ã®å®ç¾©ããlibrariesãã«å½åããå称ã«æ¸ãæããã
ãlibrariesãã®å称ã¯ã±ããã±ã¼ã¹ã ããbuild.gradleã§æå®ããéã«ã¯ãã.ãåºåãã§è¨è¿°ããã
ã¾ããå称ã®æ¥é è¾ã¨ãã¦ãlibs.ãã追å ããã
以ä¸ã«ä¿®æ£ä¾ã示ãã
plugins { id 'java' id 'org.springframework.boot' version '2.7.15' id 'io.spring.dependency-management' version '1.0.15.RELEASE' } group = 'com.example' version = '1.0.0' java { sourceCompatibility = '17' } repositories { mavenCentral() } dependencies { // Spring implementation 'org.springframework.boot:spring-boot-starter' developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' // Apache Commons Lang3 // â ä¿®æ£ implementation libs.commons.lang3 // JUnit // â ä¿®æ£ testImplementation libs.junit } tasks.named('test') { useJUnitPlatform() }
ãã©ã°ã¤ã³ã®å®ç¾©ãè¨è¿°ããï¼libs.versions.tomlï¼
ãlibs.versions.tomlãã®ãpluginsãã«ãã©ã°ã¤ã³ã®å®ç¾©ã追å ããã以ä¸ã¯io.spring.dependency-managementã®å®ç¾©ã追å ããä¾ã§ããã
ãã®æããã©ã°ã¤ã³ã«å¯¾ãã¦å½åãè¡ãããã±ããã±ã¼ã¹ï¼ãã¤ãã³åºåãï¼ã§è¨è¿°ããã
[versions] junitVersion = 5.9.1 [libraries] commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = "3.12.0" } junit = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junitVersion" } [plugins] dependency-management = { id = "io.spring.dependency-management", version = "1.0.15.RELEASE" }
ãã¼ã¸ã§ã³Noããversionsãã«å¥å®ç¾©åãããã¨ãã§ããã以ä¸ã¯org.springframework.bootã®å®ç¾©ã追å ããä¾ã§ããã
ãã®å ´åããã©ã°ã¤ã³ã®å®ç¾©ã®ãã¼ã¸ã§ã³ã®æå®ã®ãã¼ããversion.refãã¨ãªããå¤ã«ã¯ãversionsãã«å®ç¾©ããå¤æ°åãæå®ããã
[versions] junitVersion = "5.9.1" springBootPlugin = "2.7.15" [libraries] commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = "3.12.0" } junit = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junitVersion" } [plugins] dependency-management = { id = "io.spring.dependency-management", version = "1.0.15.RELEASE" } spring-boot-plugin = { id = "org.springframework.boot", version.ref = "springBootPlugin" }
ãã©ã°ã¤ã³ã®å®ç¾©ãä¿®æ£ããï¼build.gradleï¼
ãã©ã°ã¤ã³ã®å®ç¾©ããpluginsãã«å½åããå称ã«æ¸ãæããã
ãpluginsãã®å称ã¯ã±ããã±ã¼ã¹ã ããbuild.gradleã§æå®ããéã«ã¯ãã.ãåºåãã§è¨è¿°ããã
å称ã®æ¥é è¾ã¨ãã¦ãlibs.plugins.ãã追å ããã
Version Catalogãåç
§ããå®ç¾©ã®å ´åãidãã§ã¯ãªãã¦ãaliasãã¨ãã¦è¨è¼ãã
以ä¸ã«ä¿®æ£ä¾ã示ãã
plugins { id 'java' // â ä¿®æ£ alias libs.plugins.spring.boot.plugin // â ä¿®æ£ alias libs.plugins.dependency.management } group = 'com.example' version = '1.0.0' java { sourceCompatibility = '17' } repositories { mavenCentral() } dependencies { // Spring implementation 'org.springframework.boot:spring-boot-starter' developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' // Apache Commons Lang3 implementation libs.commons.lang3 // JUnit testImplementation libs.junit } tasks.named('test') { useJUnitPlatform() }
åè
Gradleã®Version catalogã使ã£ãã©ã¤ãã©ãªç®¡ç
ãã«ãããã¼ã¸ã§ã³ ã«ã¿ãã°ã«ç§»è¡ãã