How can I exclude compiled classes from an EAR (using the ear plug-in)


(richard murray) #1

In a single project I am using the war and ear plugins. The war is getting generated correctly but I have a small problem with the EAR. I don’t want the compiled classes from the project in the EAR (as these are put into the WAR).

I’ve tried adding an exclude on .class files (see example below) and this almost works. I still end up with a lot of empty directories being put into the EAR (the directories the compiled classes are in). Setting includeEmptyDirs = false doesn’t seem to make any difference, the empty dirs are still getting included.

Is there any other way to exclude the classes from the EAR? I see from other examples that have been posted that a lot of people have their WAR and EAR projects split out separately - is this the recommended approach? Ours have been combined like this since migrating from our old Ant build.

ear {
        appDirName 'sun/skeleton'
// use application metadata found in this folder
        baseName = 'arcCentreGui'
         exclude '**/*.class'
     //don't include compiled classes (these should be in WAR)
                includeEmptyDirs = false
        from war.archivePath
     //add gui.war file
        manifest = project.manifest { from sharedManifest }
    }
          ear.dependsOn war

(René Groeschke) #2

Personally, I tend to split the ear and the war into different subprojects. Your snippet looks okay for me. One tiny thing. you can change the dependency to the war by replacing from war.archivePath to war.outputs.files. This auto wiring makes “ear.dependsOn war” superfluous.

regards, René