본문 바로가기
software engineering/java

gradle의 method 선언과 prop 선언의 차이

by _블로그 2021. 4. 16.

아래는 sourceSets 설정의 예입니다. 첫번째 소스는 prop으로 선언했고 두번째 소스는 method로 선언했습니다.

 

srcDirs property

sourceSets {
    main {
         java {
            srcDirs = ['thirdParty/src/main/java']
         }
    }
}

srcDir method

sourceSets {
    main {
        java {
            srcDir 'thirdParty/src/main/java'
        }
    }
}

 

docs.gradle.org/current/userguide/building_java_projects.html#sec:custom_java_source_set_paths

 

두 설정의 차이는 prop 설정은 set의 개념으로 value를 replace하고, method를 이용한 설정은 기존에 있던 value는 그대로 두고 추가하는 개념입니다.

 

Crucially, we’re using the method srcDir() here to append a directory path, whereas setting the srcDirs property replaces any existing values. This is a common convention in Gradle: setting a property replaces values, while the corresponding method appends values.

 

method의 동작이 직관적이지 않은데 prop 설정으로만 통일하는 것이 직관적으로 생각됩니다. 이 동작은 Gradle 전반에 공통적으로 적용되는 convention이라고 합니다.

 

 

LIST

'software engineering > java' 카테고리의 다른 글

Spring Boot VS Quarkus  (0) 2022.11.07
이모지 제거  (0) 2022.02.04
Spring Boot - Logging  (0) 2021.04.26

댓글