본문 바로가기
Programming/Analyze Open Source

Spring Framework 소스 분석 스타트! (Bill Of Material ??)

by TinKerBellBass 2022. 4. 7.
728x90
반응형

끝이 나지 않는 공부가 무엇이 있을까 고민해 봤는데
방대하고 끊임없이 개발되고 있는 Spring Framework 소스 분석이 최고일 것 같다는 생각이 들었다.
먼저 srping framework 리포지토리를 포크해서 로컬로 받은 다음 스타트!

 

GitHub - spring-projects/spring-framework: Spring Framework

Spring Framework. Contribute to spring-projects/spring-framework development by creating an account on GitHub.

github.com

 

Gradle Build File

제일 먼저 까 볼 파일은 setting.gradle 파일.
srping 접두어가 붙은 수많은 모듈(프로젝트)들로 구성된 gradle multi module project 로 되어 있고
각 모듈들의 빌드 파일은 프로젝트이름.gradle 로 나누어 놓았다.

include "spring-aop"
include "spring-aspects"
include "spring-beans"
include "spring-context"
include "spring-context-indexer"
include "spring-context-support"
include "spring-core"
include "spring-core-test"
include "spring-expression"
include "spring-instrument"
include "spring-jcl"
include "spring-jdbc"
include "spring-jms"
include "spring-messaging"
include "spring-orm"
include "spring-oxm"
include "spring-r2dbc"
include "spring-test"
include "spring-tx"
include "spring-web"
include "spring-webflux"
include "spring-webmvc"
include "spring-websocket"
include "framework-bom"
include "integration-tests"

rootProject.name = "spring"
rootProject.children.each {project ->
	project.buildFileName = "${project.name}.gradle"
}

다음으로 볼 파일은 루트 디렉터리에 있는 build.gradle 파일.
파일을 열어보면 처음 보는 플러그인과 태스크들이 가득하다.

환경변수 설정 부분
moduleProjects 배열에 모든 모듈들을 넣고 있고
javaProjects 배열에는 moduleProjects 배열에서 framework-bom 모듈을 제거해서 넣고 있다.

ext {
	moduleProjects = subprojects.findAll { it.name.startsWith("spring-") }
	javaProjects = subprojects - project(":framework-bom")
	withoutJclOverSlf4j = {
		exclude group: "org.slf4j", name: "jcl-over-slf4j"
	}
}

import 부분
규모가 큰 프로젝트에서 라이브러리 의존성 버전이 한 번 꼬이면 지옥으로 가버리는 사태를 방지하기 위해
모든 프로젝트에 mavenBom 으로 라이브러리 의존성 버전을 관리해 주고 있다.

configure(allprojects) { project ->
	apply plugin: "io.spring.dependency-management"

	dependencyManagement {
		imports {
			mavenBom "com.fasterxml.jackson:jackson-bom:2.13.1"
			mavenBom "io.netty:netty-bom:4.1.75.Final"
			mavenBom "io.projectreactor:reactor-bom:2020.0.17"
			mavenBom "io.r2dbc:r2dbc-bom:Borca-RELEASE"
			mavenBom "io.rsocket:rsocket-bom:1.1.1"
			mavenBom "org.eclipse.jetty:jetty-bom:11.0.8"
			mavenBom "org.jetbrains.kotlin:kotlin-bom:1.6.20"
			mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.0"
			mavenBom "org.jetbrains.kotlinx:kotlinx-serialization-bom:1.3.2"
			mavenBom "org.junit:junit-bom:5.8.2"
		}

mavenBom ??

BOM - Bill Of Material 은 자재명세서로 프로그래밍에 한정돼서 사용되는 단어는 아닌데,

디펜던시 명세서 정도로 이해하면 된다.
maven repository 에 가서 Jackson BOM 을 찾아보면 다른 라이브러리와 달리
Managed Dependencies 리스트를 볼 수 있고 디펜던시 버전이 지정되어 있다.
그래서 mavenBom 을 임포트 하면 저 버전들로 관리가 된다고 생각하면 된다.


Jackson BOM 의 깃헙 리포지토리를 보면 maven pom.xml 파일이 있고
파일을 열어보면 의존성을 설정하는 스크립트로 가득 차 있다.
그래서 mavenBom??

 

GitHub - FasterXML/jackson-bom: Bill of materials POM for Jackson projects

Bill of materials POM for Jackson projects. Contribute to FasterXML/jackson-bom development by creating an account on GitHub.

github.com


Bom 을 Gradle 로 만들기??
framework-bom 폴더(패키지)를 열어보면 framework-bom.gradle 파일 하나가 덩그러니 놓여 있다.
constraints에서 spring-core-test 를 제외한 모든 모듈을 이름으로 정렬해서 디펜던시 정의를 가져와서
publishing 에서 Bom 을 만들어서 배포하고 있다.
java-platform 플러그인의 components.javaPlatform 이 Bom 을 만드는 부분이다.

dependencies {
   constraints {
      parent.moduleProjects.findAll{ it.name != 'spring-core-test' }.sort{ "$it.name" }.each {
         api it
      }
   }
}

publishing {
   publications {
      mavenJava(MavenPublication) {
         artifactId = 'spring-framework-bom'
         from components.javaPlatform
      }
   }
}

자세한 내용은 gradle 공식문서에서 확인할 수 있다.
Publishg flatforms 챕터에서 components.javaPlatform 을 찾아볼 수 있다.

 

The Java Platform Plugin

Because a Java Platform is a special kind of component, a dependency on a Java platform has to be declared using the platform or enforcedPlatform keyword, as explained in the managing transitive dependencies section. For example, if you want to share depen

docs.gradle.org


스프링 프레임워크의 build.gradle 파일만 확실히 파악할 수 있다면
어떠한 build.gradle 스크립트도 쓸 수 있을 것 같다.
스프링 프레임워크의 깃헙 배포 관련해서는 gradle 폴더의 publications.gradle 을 살펴보면 좋다.
스프링 프레임워크의 소스 분석이 목적이기에 이 정도로만 하고 넘어가고 다음부터는 실제로 소스를 분석해 볼까 한다.

728x90
반응형

'Programming > Analyze Open Source' 카테고리의 다른 글

[Spring -Beans] BeanFactory Interface #1  (2) 2022.04.17

댓글