Custom log4j.properties location

Hi everyone,

I’m using the eclipse plugin for gradle to manage dependencies and customize the classpath of my existing web project.

By the following build script i’ve removed all the entries from classpath and added two separated source location to classpath (main and test), each one with his own output folder. Here’s my build.gradle script:

import org.gradle.plugins.ide.eclipse.model.SourceFolder 

apply plugin: "eclipse"
apply plugin: "java"

repositories { jcenter() }
dependencies { testCompile "junit:junit:4.11",
                           "org.mockito:mockito-all:1.10.19"}       

eclipse.classpath.file {
    beforeMerged { classpath -> 
            classpath.entries.removeAll { entry ->
                   entry.kind == 'src' || entry.kind == 'output'
              }
    }

    whenMerged {  cp ->
        cp.entries.add(new SourceFolder('src/main','/build/classes/main'))
        cp.entries.add(new SourceFolder('src/test','/build/classes/test')) 
        cp.entries.removeAll { it.kind == "output" }
    }
}

Notice that there is only two dependencies. Unfortunately all other libs are put into eclipse build path manually :slight_smile:

With gradle eclipse command the eclipse project is compiled correctly.

Both this source locations (/src/main and /src/test) contains a log4j.properties file. When i build the project with eclipse, those files are correctly copied inside the classes/main and classes/test folder.

With this configuration i tried to launch a junit test, whose source file is contained in /src/test folder.

But logger doesn’t work.

i have executed the test with log4j in debug mode, and i verified that it cannot find log4j.properties file.

I put log4j.properties file in /WEB-INF/classes path and it works correctly :open_mouth:

Is there a way with gradle/groovy to put log4j.properties in custom location?

I’ve read some other topics in which someone said that the correct location is src/main/resources but i would not create this structure only for the log4j.properties fiile.

Thanks in advance,
Paolo