Question

I am migrating a legacy application from Ant to Gradle. The requirement is to build a zip file with a certain folder structure which is used by the deployment team. I am able to create the zip file in the correct format, so-far-so-good.

I am able to open the project in Eclipse, but cannot run it. In Eclipse (and IntelliJ) I need src/main/conf to be added to Eclipse's classpath, but not be included in the JAR (e.g. if I were to run gradle jar).

This is how the project is currently structured:

src
    /main
        /java
            /com
                /example
                    /App.java
        /resources
            /applicationConfiguration.xml
        /conf
            /dev.properties
            /staging.properties
            /prod.properties

How can I add the conf folder to Eclipse's classpath so that it is not included in the JAR that Gradle creates?

Was it helpful?

Solution

Given the limitations of Gradle's EclipseClasspath API, the most straightforward solution I can think of is to declare src/main/conf as another source directory:

sourceSets.main.java.srcDir "src/main/conf"

As long as the directory doesn't contain any Java files, this won't affect the outcome of the Gradle build. However, the directory will show up as a source directory in Eclipse, and its properties files will therefore be copied into the Eclipse output directory.

OTHER TIPS

Another tip. If you need it to run in Eclipse WTP, then I set the sourceDirs property of eclipse.wtp.component:

eclipse {

    project {
        natures 'org.eclipse.wst.common.project.facet.core.nature',
                'org.eclipse.wst.common.modulecore.ModuleCoreNature',
                'org.eclipse.wst.jsdt.core.jsNature'

        name 'blah-blah'

    }

    wtp {
        facet {
            facet type: 'fixed', name: 'wst.jsdt.web'
            facet name: 'java', version: '1.7'
            facet name: 'jst.web', version: '3.0'
            facet name: 'wst.jsdt.web', version: '1.0'
        }

        component {

            sourceDirs = new HashSet([
                    new File(project.getProjectDir().getAbsolutePath() + "/src/main/java"),
                    new File(project.getProjectDir().getAbsolutePath() + "/src/main/resources"),
                    new File(project.getProjectDir().getAbsolutePath() + "/src/main/conf")
            ])
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top