Gradle - Add folder to Eclipse path

I am migrating an outdated application from Ant to Gradle. The requirement is to create a zip file with a specific folder structure that is used by the deployment team. I can create a zip file in the correct format, so good.

I can open the project in Eclipse, but I can not start it. In Eclipse (and IntelliJ) I need to add src/main/conf to the Eclipse class path, but it will not be included in the JAR (for example, if I had to run the gradle jar ).

This is how the project is structured:

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

How to add a conf folder to the path to Eclipse so that it is not included in the JAR that creates Gradle?

+4
source share
2 answers

Given the limitations of the Gradle EclipseClasspath API, the easiest 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 does not contain Java files, this will not affect the result of the Gradle build. However, the directory will display as the source directory in Eclipse, so its property files will be copied to the Eclipse output directory.

+4
source

One more tip. If you need to run it in Eclipse WTP , I set the sourceDirs property 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") ]) } } 
+1
source

Source: https://habr.com/ru/post/1496529/


All Articles