当前位置: 首页 > 知识库问答 >
问题:

从脂肪罐中除去所有不必要的脂肪

谈萧迟
2023-03-14

我正在用Spring Boot,Jpa和MySQL连接器编写java控制台应用程序。我怎样才能轻松地排除所有不必要的脂肪从我的脂肪罐?

buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
//        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.2.0'
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'ca.cutterslade.analyze'

sourceCompatibility = 1.8
targetCompatibility = 1.8

ext {
    mysqlVersion = '6.0.6'
    hibernateVersion = '5.2.12.Final'
}

repositories {
    mavenCentral()
}

dependencies {
//    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final'
//    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.12.Final'
//    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
//    compile group: 'org.springframework.boot', name: 'spring-boot', version: '1.5.9.RELEASE'
//    compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.0.Final'
//    compile group: 'org.springframework', name: 'spring-context', version: '4.3.13.RELEASE'
//    compile group: 'org.springframework', name: 'spring-beans', version: '4.3.13.RELEASE'
//    compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.9.RELEASE'
//    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
//    compile group: 'org.springframework', name: 'spring-tx', version: '2.5.4'
//    compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.9.RELEASE'
//    testCompile group: 'org.springframework.boot', name: 'spring-boot-test', version: '1.5.9.RELEASE'
//    testCompile group: 'junit', name: 'junit', version: '4.12'
//    testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.13.RELEASE'



    compile group: 'mysql', name: 'mysql-connector-java', version: mysqlVersion
    compile group: 'org.hibernate', name: 'hibernate-core', version: hibernateVersion
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

jar {
    baseName 'ReportGenerator'
    version '1.0'
}
usedUndeclaredArtifacts: 
 - org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
 - org.springframework.boot:spring-boot:1.5.9.RELEASE
 - org.springframework:spring-context:4.3.13.RELEASE
 - org.springframework:spring-beans:4.3.13.RELEASE
 - org.springframework.boot:spring-boot-autoconfigure:1.5.9.RELEASE
 - org.slf4j:slf4j-api:1.7.25
 - org.springframework:spring-tx:4.3.13.RELEASE
 - org.springframework.data:spring-data-jpa:1.11.9.RELEASE
unusedDeclaredArtifacts: 
 - mysql:mysql-connector-java:6.0.6
 - org.hibernate:hibernate-core:5.2.12.Final
 - org.springframework.boot:spring-boot-starter-data-jpa:1.5.9.RELEASE

共有1个答案

吕永嘉
2023-03-14

几个建议。

  1. 在项目上使用dependency:Analyse,它将列出未使用的依赖项,您可以排除或消除这些依赖项。
  2. 对pom中的每一个依赖项都使用 属性,这可以大大减小脂肪罐的大小。提供正确的作用域参数,如compile、test...
 类似资料:
  • 我使用JarSplice创建了一个胖jar文件,但是当我启动它时,我得到一个窗口(大小可以),它在半秒后关闭。。。 在“addjars”部分中,我添加了从Eclipse导出的jar文件,以及我正在使用的所有库jar。在本机部分,我只为lwjgl添加Windows本机。我想我写了正确的主类。 我做错了什么?我怎样才能解决这个问题? 注意:我使用的是最新版本的eclipse和jdk。

  • 我将Gradle用于一个简单的Java项目,并希望生成一个fat JAR,其中还包含源代码。 我准备了一个示例存储库:https://github.com/szarnyasg/gradle-shadowjar-source.我尝试了这个配置: 我可以通过以下方式构建此功能: 这将在目录中生成两个JAR文件: -没有源的胖JAR -一个(仅)包含源的JAR Gradle Shadow插件的文档说明

  • 我在Java 8应用程序中使用了处理,它在IntelliJ上运行良好。Gradle导出所有平台的fat jar(下面的代码)打包依赖项后出现问题: 每当我试图打开扩展PApplet的窗口时,它都会引发以下异常: 通用域名格式。约甘普。opengl。GLException:配置文件[GL4bc、GL4、GL3bc、GL3、GLS3、GL2、GLS2]在设备窗口GraphicsDevice[type.

  • 我知道不是一个有效的阶段,但我只是想说明我试图完成什么,即只有在提供选项时才构建fat jar的条件安装。

  • 我对Gradle和shadow jar(Maven的Shade插件的Gradle版本)是新手。我正在构建一个胖jar,我想在其中合并服务文件(这就是我首先使用shadowjar的原因)。根据文档,shadowJar任务继承自gradle Jar任务。因此,我们可以假设它将完全像jar任务一样工作。 下面是jar任务的片段: 结果,它产生了一个脂肪罐与所有的依赖关系爆炸,什么是预期的。当我将任务名称

  • 我有一个使用spark的scala多项目,并尝试使用sbt插件sbt-assembly 0.14.3来制作一个胖罐子。我的建筑。SBT看起来像这样: 我想创建一个子项目的fat jar,以便这个fat jar包含项目核心的所有库和代码。我尝试了以下方法: