Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: ear deploymentDescriptor - Exclude module from application.xml

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!

like image 544
StormeHawke Avatar asked Nov 12 '22 19:11

StormeHawke


1 Answers

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 )
    }
}
like image 110
cmcginty Avatar answered Nov 28 '22 02:11

cmcginty