无法使用Gradle输出jar文件

瓦西列维奇

我有一个项目,它具有多个主类文件,我可以在IDE(intelij)中编译并运行该项目,但是无法弄清楚如何使用gradle输出工件jar,这是我尝试的方法:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        // Add this line
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1"
        classpath 'gradle.plugin.edu.sc.seis.gradle:launch4j:1.6.2'
    }
}


group 'polisotinserter'
version '1.0.0'

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'edu.sc.seis.launch4j'
sourceCompatibility = 1.8

repositories {
    jcenter()
    maven {
        url 'https://artifactory.lyoko.pw:443/libs-release-local'
    }
}

dependencies {
    compile group: 'com.github.axet', name: 'lookup', version: '0.1.30'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.0.1'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-ie-driver', version: '3.0.1'
    compile "org.jsoup:jsoup:1.8.3"
    compile group: 'javax.mail', name: 'mail', version: '1.4.7'

    compile(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
    compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    compile group: 'org.json', name: 'json', version: '20160810'


    compile(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
    compile(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
    compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
    compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')

}

subprojects {
    apply plugin: 'java'
    repositories {
        jcenter()
        maven {
            url 'https://artifactory.lyoko.pw:443/libs-release-local'
            credentials {
                username = "vasilevich"
                password = "APkgGZjFzEM6Kp1yj1Be3fyrKW"
            }
        }
    }
    sourceSets {
        main {
            java {
                srcDir 'src/'
            }
        }
    }
    dependencies {
        compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
        compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
    }
}


project(':CGFetcher') {
    dependencies {
        compile "org.jsoup:jsoup:1.8.3"
        compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    }
    task assembleRelease(type: Jar) {
        classifier = 'release'
        manifest {
            attributes 'Implementation-Title': "CGFetcher",
                    'Implementation-Version': project.version,
                    'Main-Class': 'gui.CGGuiMain'
        }
        baseName = "CGFetcher"
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        with jar
    }
    artifacts {
        archives assembleRelease
    }
}

在我使用

gradle build

我在build / libs文件夹中得到一个jar,这个文件夹称为polisotinserter-1.0.0.jar,这是无法预料的,​​而且jar不包含我在project()指令中设置的清单。

经过几次测试后,似乎project()指令根本没有运行,所以我很困惑从何去何从?我怎样才能让gradle运行

project(':CGFetcher') {

指示?感谢您的关注。

瓦西列维奇

好的问题是,它不应该出现在项目的根目录中,我注意到,当我运行gradle build时,它还会创建一个子文件夹CGFetcher,而该子文件夹又具有自己的生成文件夹和相关的jar。此外,我注意到它没有使用根项目的源代码,因此我必须这样做:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        // Add this line
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1"
        classpath 'gradle.plugin.edu.sc.seis.gradle:launch4j:1.6.2'
    }
}


group 'polisotinserter'
version '1.0.0'

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'edu.sc.seis.launch4j'
sourceCompatibility = 1.8

repositories {
    jcenter()
    maven {
        url 'https://artifactory.lyoko.pw:443/libs-release-local'
    }
}

dependencies {
    compile group: 'com.github.axet', name: 'lookup', version: '0.1.30'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.0.1'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-ie-driver', version: '3.0.1'
    compile "org.jsoup:jsoup:1.8.3"
    compile group: 'javax.mail', name: 'mail', version: '1.4.7'

    compile(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
    compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    compile group: 'org.json', name: 'json', version: '20160810'


    compile(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
    compile(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
    compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
    compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')

}
sourceSets {
    main {
        java {
            srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
        }
        resources {
            srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
        }
    }
}

subprojects {
    apply plugin: 'java'
    repositories {
        jcenter()
        maven {
            url 'https://artifactory.lyoko.pw:443/libs-release-local'
            credentials {
                username = "vasilevich"
                password = "APkgGZjFzEM6Kp1yj1Be3fyrKW"
            }
        }
    }

    sourceSets {
        main {
            java {
                srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
            }
            resources {
                srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
            }
        }
    }
    dependencies {
        compile group: 'com.github.axet', name: 'lookup', version: '0.1.30'

        compile "org.jsoup:jsoup:1.8.3"
        compile group: 'javax.mail', name: 'mail', version: '1.4.7'

        compile(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
        compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
        compile group: 'org.json', name: 'json', version: '20160810'


        compile(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
        compile(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
        compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
        compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')


    }
}

project(':CGFetcher') {

    task assembleRelease(type: Jar) {
        classifier = 'release'
        manifest {
            attributes 'Implementation-Title': "CGFetcher",
                    'Implementation-Version': project.version,
                    'Main-Class': 'gui.CGGuiMain'
        }
        baseName = "CGFetcher"
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        with jar
    }
    artifacts {
        archives assembleRelease
    }
}

注意:

sourceSets {
        main {
            java {
                srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
            }
            resources {
                srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
            }
        }
    }

这告诉项目使用根源代码。但是现在出现了一个新问题,我不知道如何为不同的项目创建不同的依赖关系,似乎gradle迫使我使用所有依赖关系,即使它们没有在代码中被强制使用,也仅仅是因为包含了类。编辑:好的,我认为这太简单了,给您的所有子项目compileOnly(在较早的gradle版本中提供),然后在实际项目中添加“ compile”,这是一个示例:

subprojects {
    apply plugin: 'java'
    repositories {
        jcenter()
        maven {
            url 'https://artifactory.lyoko.pw:443/libs-release-local'
            credentials {
                username = "vasilevich"
                password = "APkgGZjFzEM6Kp1yj1Be3fyrKW"
            }
        }
    }

    sourceSets {
        main {
            java {
                srcDir new File(rootProject.projectDir, "src/main/java").getAbsolutePath()
            }
            resources {
                srcDir new File(rootProject.projectDir, "src/main/resources").getAbsolutePath()
            }
        }
    }
    dependencies {
        compileOnly group: 'com.github.axet', name: 'lookup', version: '0.1.30'
        compileOnly group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.0.1'
        compileOnly group: 'org.seleniumhq.selenium', name: 'selenium-ie-driver', version: '3.0.1'
        compileOnly group: 'javax.mail', name: 'mail', version: '1.4.7'
        compileOnly(group: 'EnglishToHebrewTranslicirator', name: 'EnglishToHebrewTranslicirator', version: 'EnglishToHebrewTranslicirator')
        compileOnly group: 'org.json', name: 'json', version: '20160810'
        compileOnly(group: 'AbstractConnectionApi', name: 'AbstractConnectionApi', version: '1.0.0')
        compileOnly(group: 'sjxlsx-custom', name: 'sjxlsx-custom', version: '1.0.0')
        compileOnly "org.jsoup:jsoup:1.8.3"
        compileOnly(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
        compileOnly(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
        compileOnly group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'

    }
}

project(':CGFetcher') {
    dependencies {
        compile "org.jsoup:jsoup:1.8.3"
        compile(group: 'programupdater', name: 'Programs-Updater', version: '1.0.0')
        compile(group: 'com.intellij', name: 'forms_rt', version: '7.0.3+')
        compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'

    }
    task assembleRelease(type: Jar) {
        classifier = 'release'
        manifest {
            attributes 'Implementation-Title': "CGFetcher",
                    'Implementation-Version': project.version,
                    'Main-Class': 'gui.CGGuiMain'
        }
        baseName = "CGFetcher"
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        with jar
    }
    artifacts {
        archives assembleRelease
    }
}

这不会导致任何错误,并且所产生的jar会像其预期的那样小。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用gradle在构建时在项目中包括本地jar文件

在JAR文件和运行时库路径中包括子项目gradle构建输出

无法使用Gradle和Kotlin运行生成的JAR文件

Gradle清理并复制JAR文件

Gradle错误-无法下载okhttp.jar文件2.7.2

JavaFX 11:使用Gradle创建一个jar文件

使用Gradle和ProGuard的Android Build:“必须在输入jar之后指定输出jar,否则它将为空”

无法运行通过gradle编译的groovy代码构建的jar文件

Gradle jar任务失败,并显示“在最新检查期间无法捕获任务'jar'属性'archivePath'的输出文件快照”。

如何使用Gradle创建独立的自执行jar文件?

使用Fastlane Gradle时如何指定输出.apk文件路径?

在gradle android build中使用progaurd生成jar文件

无法为Gradle项目创建JAR文件

无法使用Gradle和Intellij导入jar文件依赖项

Gradle无法使用OBJECT库构建CMake项目,因为它需要输出文件

无法使用g ++从多个文件接收正确的输出

Gradle无法使用Docker依赖构建JAR

无法使用对象从外部文件输出JSON数据

无法使用Java打开.jar文件

无法jar -tvf jar文件

无法使用.desktop访问.jar文件

在使用cron引导时运行jar文件并查看输出

使用Gradle解析文件系统中的jar

无法使用 Pandas 从 tsv 文件中获得正确的输出

无法使用 gradle 生成的 jar 文件找到或加载主类

无法覆盖使用输出重定向退出文件>

使用 Gradle 构建 JAR 时生成插件 .dat 文件

使用 Gradle 使用多层 jar 文件创建优化的 docker 镜像

在 IntelliJ IDEA 中使用 Gradle 导出 JAR 文件时,Resources 文件夹不包含在 JAR 文件中