Gradle Buildship Plugin - Add a folder to eclipse classpath only but don't include war file

I’m using gradle-7.5.1 and i have a spring boot application and this is my structure:

I’ve moved configurations files like application,properties, messages.properties, some json files etc to external conf folder which is in parallel to “src” so that customizations can be done to configuration files without re-building war.

But for local development, when i run as SpringBootApplication in eclipse which uses embedded tomcat, i need to set that folder in classpath so that application runs fine. I want to set it in build.gradle itself so that whenever project imported into eclipse, it will be set automatically without manually setting it like this:

image

I tried multiple ways, but none of them are satisfactory:

  1. I tried setting conf folder as additional resources directory. This works fine in eclipse because conf folder contents getting copied WEB-INF\classes which i don’t want because when i’m building war these are being included into war file which i want to exclude because when i deployed this war file to external tomcat, each server will have its own conf directory and set it in tomcat CLASSPATH.
sourceSets {
    main {
        resources {
            srcDirs 'conf' //specify additional resources directory apart from src/main/resources
        }
    }
}
  1. Had this configuration.
// Eclipse plugin configuration
eclipse {
    classpath {
        file {
            withXml {
                def node = it.asNode()
                node.appendNode('classpathentry', [kind: 'lib', path: 'conf'])
            }
        }
    }
}

This works when i’m running gradle eclipse from command line but not working with Eclipse Gradle -> Refresh Project

  1. Tried this
eclipse.classpath.file {
  whenMerged { classpath ->
    def lib = new org.gradle.plugins.ide.eclipse.model.Library(fileReference(file('conf')))
    lib.exported = true
    classpath.entries << lib
  }
}

But this is adding inside Project & External Dependencies section, due to this, im not able to edit the files:

image

So this is my problem summary:

i want a folder to be added in eclipse classpath to run the application locally but not to be included in war file.

Got it. Finally this worked. Instead of setting conf folder as Library, setting it as SourceFolder solved all my problems.

eclipse.classpath.file {
  whenMerged { classpath ->
    classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder('conf',null))
  }
}

This sets conf folder as source folder only in eclipse and able to edit files as well, but won’t copy the contents of it while building war file.

image

Sharing the solution if anyone needs it in future like me. :slight_smile:

1 Like