본문 바로가기
JAVA

jar 파일 빌드 시 테스트 파일 제외

by 고체물리학 2024. 7. 25.
jar 파일로 빌드 시에 test 파일에서 에러 나거나 용량을 줄이고 싶다면 test 파일을 제외한 후 빌드할 수 있다

 

 
  •  Maven 사용
1. pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>your-artifact-id</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- 필요한 의존성을 여기에 추가 -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <excludes>
                        <exclude>**/test/**</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
 
2. mave.test.skip
mvn clean package -Dmaven.test.skip=true
 
3. pom.xml (추가)

<properties> <maven.test.skip>true</maven.test.skip> </properties>
 
  • Gradle
1. groovy
jar {
    exclude '**/test/**'
}
 
2. build.gradle.kts
plugins {
    kotlin("jvm") version "1.8.10"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib"))
}

// 'test' 태스크를 실행하지 않도록 설정
tasks.withType<Test> {
    enabled = false
}

tasks.jar {
    // 'src/test' 폴더를 제외
    exclude("**/test/**")
}
 

 

반응형

댓글