Gradle: ear deploymentDescriptor - Exclude module from application.xml

 ̄綄美尐妖づ 提交于 2020-01-03 13:24:21

问题


I have the following in my gradle build file. My problem is that log4j.properties is being added as an ejb module in application.xml, despite my attempt to remove it from the xml per the thread here:

http://forums.gradle.org/gradle/topics/ear_plugin_inserts_unneeded_ejb_modules_in_the_application_xml_ear_descriptor

apply plugin: 'ear'

ear {

    deploymentDescriptor {
        applicationName = 'ourapp'
        displayName = 'ourapp'
        initializeInOrder = true

            //This doesn't work:
        withXml { xml ->
            xml.asNode().module.removeAll { it.ejb.text.equals('log4j.properties') }
        }
    }
    //Add log4j.properties to ear root
    from('../../lib/log4j.properties', 'log4jProperties')
}


dependencies
{
    deploy 'javax:javax.jnlp:1.2'
    deploy 'com.oracle:ojdbc6:1.6.0'

    earlib 'org.apache:apache-log4j:1.2.16'
}

How can I get the gradle to exclude log4j.properties from application.xml?

EDIT

This is causing a failure to start up in my application server (JBoss 6.0.0) because it doesn't know what to do with log4j.properties. I can work around it by manually creating my application.xml file, but that makes for another thing that has to be maintained. Any assistance would be welcome!


回答1:


This code works for me. You need to protect the 'remove' method with an 'if' block because the closure is called multiple times. I found that the first time its called, log4jNode is set to 'null'.

withXml {
    def log4jNode = asNode().module.find { it.ejb.text() == 'log4j.properties' }
    if (log4jNode) {
        asNode().remove( log4jNode )
    }
}


来源:https://stackoverflow.com/questions/19692016/gradle-ear-deploymentdescriptor-exclude-module-from-application-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!