diff --git a/grails-boot/src/main/groovy/org/grails/boot/context/GrailsDevelopmentModeWatchApplicationContextInitializer.java b/grails-boot/src/main/groovy/org/grails/boot/context/GrailsDevelopmentModeWatchApplicationContextInitializer.java index e14171c452..59b6b14aef 100644 --- a/grails-boot/src/main/groovy/org/grails/boot/context/GrailsDevelopmentModeWatchApplicationContextInitializer.java +++ b/grails-boot/src/main/groovy/org/grails/boot/context/GrailsDevelopmentModeWatchApplicationContextInitializer.java @@ -66,6 +66,9 @@ public class GrailsDevelopmentModeWatchApplicationContextInitializer implements private static final Log logger = LogFactory.getLog(GrailsDevelopmentModeWatchApplicationContextInitializer.class); + private static final String SOURCE_MAIN_JAVA = "src/main/java"; + private static final String SOURCE_MAIN_GROOVY = "src/main/groovy"; + private boolean developmentModeActive = false; private DirectoryWatcher directoryWatcher; @@ -238,11 +241,9 @@ else if (i == 1) { changedFile = changedFile.getCanonicalFile(); // Groovy files within the 'conf' directory are not compiled boolean configFileChanged = false; - for (String dir : Arrays.asList("grails-app", "app")) { - String confPath = File.separator + dir + File.separator + "conf" + File.separator; - if (changedFile.getPath().contains(confPath)) { - configFileChanged = true; - } + String confPath = new File(BuildSettings.GRAILS_APP_DIR, "conf").getAbsolutePath(); + if (changedFile.getPath().contains(confPath)) { + configFileChanged = true; } if (configFileChanged) { pluginManager.informOfFileChange(changedFile); @@ -286,18 +287,25 @@ private void setDevelopmentModeActive(boolean active) { private void recompile(File changedFile, CompilerConfiguration compilerConfig, String location) { String changedPath = changedFile.getPath(); - String sourceMainGroovy = "src" + File.separator + "main" + File.separator + "groovy"; + String grailsAppFullPath = BuildSettings.GRAILS_APP_DIR.getAbsolutePath(); + String grailsAppPath = grailsAppFullPath.substring(grailsAppFullPath.lastIndexOf(File.separator) + 1); File appDir = null; - for (String dir : Arrays.asList("grails-app", "app", sourceMainGroovy)) { + boolean sourceFileChanged = false; + for (String dir : Arrays.asList(grailsAppPath, SOURCE_MAIN_JAVA, SOURCE_MAIN_GROOVY)) { String changedDir = File.separator + dir; if (changedPath.contains(changedDir)) { appDir = new File(changedPath.substring(0, changedPath.indexOf(changedDir))); + sourceFileChanged = true; break; } } - String baseFileLocation = appDir != null ? appDir.getAbsolutePath() : location; + if (!sourceFileChanged) { + return; + } + + String baseFileLocation = appDir.getAbsolutePath(); compilerConfig.setTargetDirectory(new File(baseFileLocation, BuildSettings.BUILD_CLASSES_PATH)); logger.debug(String.format("WatchService found file changed%nRecompiling... [%s]%n", changedFile)); @@ -359,7 +367,9 @@ public void onNew(File file) { } private void configureDirectoryWatcher(DirectoryWatcher directoryWatcher, String location) { - for (String dir : Arrays.asList("grails-app", "app", "src/main/groovy", "src/main/java")) { + String grailsAppFullPath = BuildSettings.GRAILS_APP_DIR.getAbsolutePath(); + String grailsAppPath = grailsAppFullPath.substring(grailsAppFullPath.lastIndexOf(File.separator) + 1); + for (String dir : Arrays.asList(grailsAppPath, SOURCE_MAIN_JAVA, SOURCE_MAIN_GROOVY)) { directoryWatcher.addWatchDirectory(new File(location, dir), Arrays.asList("groovy", "java")); } } diff --git a/grails-bootstrap/src/main/groovy/grails/util/BuildSettings.groovy b/grails-bootstrap/src/main/groovy/grails/util/BuildSettings.groovy index 5eb81a0390..066f0aabf9 100644 --- a/grails-bootstrap/src/main/groovy/grails/util/BuildSettings.groovy +++ b/grails-bootstrap/src/main/groovy/grails/util/BuildSettings.groovy @@ -290,22 +290,22 @@ class BuildSettings { RESOURCES_DIR = new File(projectResourceDir) } else { - RESOURCES_DIR = new File(TARGET_DIR, 'resources/main') + RESOURCES_DIR = new File(BASE_DIR, 'build/resources/main') } String projectClassDir = System.getProperty(PROJECT_CLASSES_DIR) if (projectClassDir) { CLASSES_DIR = new File(projectClassDir) - BUILD_CLASSES_PATH = projectClassDir + BUILD_CLASSES_PATH = 'build/classes/groovy/main' } else { - File groovyDir = new File(TARGET_DIR, 'classes/groovy/main') + File groovyDir = new File(BASE_DIR, 'build/classes/groovy/main') if (groovyDir.exists()) { CLASSES_DIR = groovyDir BUILD_CLASSES_PATH = 'build/classes/groovy/main' } else { - CLASSES_DIR = new File(TARGET_DIR, 'classes/main') + CLASSES_DIR = new File(BASE_DIR, 'build/classes/main') BUILD_CLASSES_PATH = 'build/classes/main' } }