使用gradle合并用于拆分包的jar

使用gradle合并用于拆分包的jar,gradle,java-9,module-info,Gradle,Java 9,Module Info,我创建了一个web应用程序。我用的是Gradle。我是Gradle的新手,我正在尝试将我的一个项目迁移到Java9模块系统。我将所有JAR移到模块路径而不是类路径。这是我的build.gradle的片段 plugins { id 'java-library' id 'eclipse-wtp' id 'war' } ext { //logging log4jGroupId = "org.apache.logging.log4j" log4jVers

我创建了一个web应用程序。我用的是Gradle。我是Gradle的新手,我正在尝试将我的一个项目迁移到Java9模块系统。我将所有JAR移到模块路径而不是类路径。这是我的build.gradle的片段

plugins {
    id 'java-library'
    id 'eclipse-wtp'
    id 'war'
}

ext {
    //logging
    log4jGroupId = "org.apache.logging.log4j"
    log4jVersion = "2.11.0"
    .....
    moduleName = "pk.training.basit.kanban"
}

dependencies {
    // Unit Testing
    testImplementation group: 'junit', name: 'junit', version: junitVersion
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterEngineVersion
    implementation group: log4jGroupId, name: 'log4j-api', version: log4jVersion
    .....
    ['log4j-core', 'log4j-jcl', 'log4j-slf4j-impl', 'log4j-web'].each {
        runtime "${log4jGroupId}:$it:${log4jVersion}"
    }

    implementation group: 'javax.transaction', name: 'javax.transaction-api', version: javaxTransactionApiVersion

    implementation (group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: jaxbVersion) {
    exclude group: 'org.jvnet.staxex', module: 'stax-ex'
    }
    ...   
}

eclipse.classpath.file {
    whenMerged {
        entries.findAll { isModule(it) }.each { it.entryAttributes['module'] = 'true' }
    }
}

boolean isModule(entry) {
    // filter java 9 modules
    entry.kind == 'lib'  // Only libraries can be modules
}

eclipse.wtp.facet.file.withXml { facetXml ->
    def root = facetXml.asNode()
    root.installed.find { it.@facet == 'jst.java' }.@version = '9'
    root.installed.find { it.@facet == 'jst.web' }.@version = '3.1'
}

compileJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath,
        ]
        classpath = files()  // Clears the classpath property by creating an empty file collection
    }
}

compileTestJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath,      // This is the default value for the classpath property used as the --module-path.
            '--add-modules', 'org.junit.jupiter.api',  // junit5 automatic module specific
            '--add-modules', 'java.xml.bind', // jaxb specific
            '--add-reads', "$moduleName=org.junit.jupiter.api", // allow junit to read your module
            '--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath, // Adds the test source files to the org.gradle.actors module.
        ]
        classpath = files()
    }
}

test {
    inputs.property("moduleName", moduleName)
    doFirst {
        jvmArgs = [
            '--module-path', classpath.asPath, 
            '--add-modules', 'ALL-MODULE-PATH', 
            '--add-reads', "$moduleName=org.junit.jupiter.api", 
            '--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath, 
        ]
        classpath = files()
    }
}
现在,如果执行gradle
build
buildDependents
testClasses
任务,则会出现以下错误

module not found: junit --> requires junit;
module not found: log4j.api -->  requires log4j.api;
module not found: org.apache.logging.log4j.web --> requires org.apache.logging.log4j.web;
error: the unnamed module reads package javax.transaction.xa from both java.sql and javax.transaction.api
error: the unnamed module reads package javax.activation from both java.activation and activation
error: the unnamed module reads package com.sun.xml.bind from both jaxb.runtime and jaxb.core
error: module spring.web reads package javax.transaction.xa from both javax.transaction.api and java.sql
error: module spring.security.core reads package javax.transaction.xa from both javax.transaction.api and java.sql
....
所以,为什么我得到了
jUnit
log4j.api
org.apache.logging.log4j.web
的模块未找到异常。我检查了模块路径,JAR就在那里

第二,我读了关于拆分包的文章。我的问题是,从错误中我知道这两个JAR是
java.sql和javax.transaction.api
jaxb.runtime和jaxb.core
,对于其他JAR也是如此

我是否可以创建一个Gradle任务,将这两个jar合并为一个,并在模块路径上包含这一个jar,以便删除这些错误?还是有其他方法来解决此类错误

是否可以将一些JAR移动到模块路径,将一些JAR移动到类路径?以及如何找到移动模块路径的JAR和移动类路径的JAR


谢谢您

只是一个调试建议,您也可以访问jvm参数,以便更好地了解所有模块的实际解决方法,您的问题解决了吗?