Custom SourceSet issue while creating war


(A Nageshwar) #1

Hi,

while executing gardle war it is including .java files in the war how to exclude all .java from war

sourceSets {
        gen {
       		java {
            	srcDir 'app/GeneratedSource'
            }
            
        }
        
        dao {
        	java {
                srcDir 'app/JavaSource'
                exclude 'gov/fd/vc/svc/**'
            }
           
            compileClasspath += gen.output
        }

        svc {
        	java {
                srcDir 'app/JavaSource'
                exclude 'gov/fd/vc/dao/**'
            }
            
            compileClasspath += gen.output
            compileClasspath += dao.output
        }

         main {
            java {
    	    	srcDir 'web/JavaSource'
            }
            resources {
    			srcDir 'app/GeneratedSource'
    			srcDir 'app/JavaSource'
    	    	srcDir 'web/JavaSource'
            }
            compileClasspath += svc.output
        }
    }

    configurations {
        genCompile.extendsFrom compile
        daoCompile.extendsFrom compile
        svcCompile.extendsFrom compile
    }

please where iam doing mistake to define custom source set.


Eclipse showing compile error if remove main
(A Nageshwar) #2

instead of main just use debug

debug {
            java {
    	    	srcDir 'web/JavaSource'
            }
            resources {
    			srcDir 'app/GeneratedSource'
    			srcDir 'app/JavaSource'
    	    	srcDir 'web/JavaSource'
            }
            compileClasspath += svc.output
        }

Eclipse showing compile error if remove main
(Stefan Oehme) #3

You are including all your .java files as resources. I’d recommend putting java and resource files in different folders. Otherwise, you’ll need to at least create exclusion rules so that .java doesn’t get packaged into the war.

Generally I don’t think separating your code into sourceSets just for some validation is a good idea. It just makes your build so much more complicated and harder for others to understand. Look into tools like SonarQube to enforce these kinds of architectural constraints.


(A Nageshwar) #4

@st_oehme

 resources {
          srcDir 'app/GeneratedSource'
          srcDir 'app/JavaSource'
          srcDir 'web/JavaSource'
          exclude '**/*.java'
        }

Can we exclude .java file like this ?