Skip to content

Commit

Permalink
If the maven wrapper is not found with the build file pom.xml then ch…
Browse files Browse the repository at this point in the history
…eck for one in the project directory (could be different).

Signed-off-by: Paul Gooderham <[email protected]>
  • Loading branch information
turkeylurkey committed Nov 8, 2023
1 parent 956f411 commit c6eaf24
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static String getMavenSettingsCmd(Project project, VirtualFile buildFile)
String mavenHome = mavenSettings.getMavenHome();
if (MavenServerManager.WRAPPED_MAVEN.equals(mavenHome)) {
// it is set to use the wrapper
return getLocalMavenWrapper(buildFile);
return getLocalMavenWrapper(project, buildFile);
} else {
// try to use maven home path defined in the settings
return getCustomMavenPath(project, mavenHome);
Expand All @@ -216,13 +216,19 @@ public static String getMavenSettingsCmd(Project project, VirtualFile buildFile)
/**
* Get the local wrapper path for Maven that is in the project level
*
* @param project the liberty project containing the application project directory
* @param buildFile the build file specified in the application project directory
* @return the Maven wrapper path to be executed or an exception to display
* @throws LibertyException
*/
private static String getLocalMavenWrapper(VirtualFile buildFile) throws LibertyException {
private static String getLocalMavenWrapper(Project project, VirtualFile buildFile) throws LibertyException {
String mvnw = SystemInfo.isWindows ? ".\\mvnw.cmd" : "./mvnw";
File wrapper = new File(buildFile.getParent().getPath(), mvnw);
File bfWrapper = null;
if (!wrapper.exists() || !wrapper.canExecute()) {
bfWrapper = wrapper;
wrapper = new File(project.getBasePath(), mvnw);
}
if (!wrapper.exists()){
String translatedMessage = LocalizedResourceUtil.getMessage("maven.wrapper.does.not.exist");
throw new LibertyException("A Maven wrapper for the project could not be found. Make sure to configure a " +
Expand All @@ -234,6 +240,11 @@ private static String getLocalMavenWrapper(VirtualFile buildFile) throws Liberty
"execute it. Consider giving executable permission for the Maven wrapper file or changing the build " +
"preferences for Maven inside IntelliJ Maven preferences.", translatedMessage);
}
if (bfWrapper != null) {
LOGGER.warn("The wrapper built from the build file is invalid, using wrapper from project directory. exists="
+ bfWrapper.exists() + " canExecute=" + bfWrapper.canExecute());
mvnw = wrapper.getAbsolutePath();
}
return mvnw;
}

Expand Down

0 comments on commit c6eaf24

Please sign in to comment.