How to add source folder to grails application

≯℡__Kan透↙ 提交于 2020-01-11 10:07:28

问题


I use STS for developing Grails application, and I need to use there a bunch of classes generated by wsimport utility. In order to not to mix my source with autogenerated source, I want to add separate directory and put there generated classes, like this:

grails-project  
 |  
 |-- .classpath  
 |-- .groovy  
 |-- .project  
 |-- .settings  
 |-- application.properties  
 |-- grails-app  
 |-- lib  
 |-- scripts  
 |-- src
 |   |-- groovy
 |   |-- java
 |   `-- wsimport     <- where I want to make additional source folder
 |-- target  
 |-- target-eclipse  
 |-- test  
 `-- web-app

I can add new classpath entry to .classpath file and STS will recognize sources, but what do I do to Grails? Do I need to specify it in some config file or something?


回答1:


The answer is here:

http://ofps.oreilly.com/titles/9781449323936/chapter_configuration.html

To summarize, you can use configuration like this:

extraSrcDirs = ["$basedir/src/extra1", "$basedir/src/extra2", ...]

eventCompileStart = {
   for (String path in extraSrcDirs) {
      projectCompiler.srcDirectories << path
   }
   copyResources buildSettings.resourcesDir
}

eventCreateWarStart = { warName, stagingDir ->
   copyResources "$stagingDir/WEB-INF/classes"
}

private copyResources(destination) {
   ant.copy(todir: destination,
            failonerror: false,
            preservelastmodified: true) {
      for (String path in extraSrcDirs) {
         fileset(dir: path) {
            exclude(name: '*.groovy')
            exclude(name: '*.java')
         }
      }
   }
}

This will let the grails compiler know about the extra source folders, but I don't think it is enough for STS to know about the source folders. For that, you will have to continue updating the project's .classpath.



来源:https://stackoverflow.com/questions/14942263/how-to-add-source-folder-to-grails-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!