Maven

springboot 的maven只能排除依赖不能排除main文件夹里面的文件,源生的maven才可以排除main里的文件

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!--只在开发过程中使用,但不打包的jar-->
                    <excludes>
                        <exclude>
                            <groupId>io.github.yedaxia</groupId>
                            <artifactId>japidocs</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <!--源生maven-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <!--不打包的内容文件-->
                        <exclude>com/fu/demo/JApiDocs.class</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

打包编译resources资源文件时异常

failed with MalformedInputException
引入resources插件,排除编译的文件类型

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <!-- 不编译,直接打包的文件类型,防止打包失败。如:xls、pdf、wrod文档等 -->
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>

Gradle

dependencies {
	implementation 'groupId:artifactId:version'//Gradle4.1新增的依赖方式,该依赖方式不会产生传递依赖
	compileOnly 'groupId:artifactId:version'//仅编译时使用,不参与打包,如:lombok只在编译时使用,编译后不需要用到
	annotationProcessor 'groupId:artifactId:version'//注解注释器,不参与打包,如:lombok使用的注解需要用到
	runtimeClasspath 'groupId:artifactId:version'//仅运行时使用,不参与编译,参与打包,如:mysql-connector-java驱动
	testCompileClasspath 'groupId:artifactId:version'//仅测试时使用,参与测试时编译,运行,不参与打包
	testRuntimeClasspath 'groupId:artifactId:version'//仅测试运行时使用,不参与编译、打包
}

bootJar {
	//排除jar
    exclude 'japidocs-1.4.4.jar'
    //排除文件
    exclude 'com/rd/fu/JApiDocs.class'
}

//打包排除的文件(不推荐)
//sourceSets{
//     main{
//         //排除java文件夹下面的文件
//         java{
//            exclude 'com/fu/gradledemo/JApiDocs.java'
//         }
//         //排除resources静态资源文件夹里面的文件
//         resources{
////         exclude 'application.yml'
//         }
//     }
//}
Logo

一站式 AI 云服务平台

更多推荐