@@ -15,6 +15,9 @@ public class BuildProject {
15
15
16
16
private static final String LIB_DEPS_DOWNLOAD_DIR = "_libdeps" ;
17
17
18
+ private static final String MAVEN_CMD = System .getProperty ("os.name" ).contains ("win" ) ? "mvn.cmd" : "mvn" ;
19
+ private static final String GRADLE_CMD = System .getProperty ("os.name" ).contains ("win" ) ? "gradlew.bat" : "gradlew" ;
20
+
18
21
private static boolean buildWithTool (String [] buildCommand ) {
19
22
Log .info ("Building the project using " + buildCommand [0 ] + "." );
20
23
ProcessBuilder processBuilder = new ProcessBuilder (buildCommand );
@@ -41,7 +44,7 @@ private static boolean buildWithTool(String[] buildCommand) {
41
44
* @return true if Maven is installed, false otherwise.
42
45
*/
43
46
private static boolean isMavenInstalled () {
44
- ProcessBuilder processBuilder = new ProcessBuilder ("mvn" , "--version" );
47
+ ProcessBuilder processBuilder = new ProcessBuilder (MAVEN_CMD , "--version" );
45
48
try {
46
49
Process process = processBuilder .start ();
47
50
BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
@@ -70,7 +73,7 @@ private static boolean mavenBuild(String projectPath) {
70
73
return false ;
71
74
}
72
75
String [] mavenCommand = {
73
- "mvn" , "clean" , "package" , "-f" , projectPath + "/pom.xml" , "-B" , "-V" , "-e" , "-Drat.skip" ,
76
+ MAVEN_CMD , "clean" , "package" , "-f" , projectPath + "/pom.xml" , "-B" , "-V" , "-e" , "-Drat.skip" ,
74
77
"-Dfindbugs.skip" , "-Dcheckstyle.skip" , "-Dpmd.skip=true" , "-Dspotbugs.skip" , "-Denforcer.skip" ,
75
78
"-Dmaven.javadoc.skip" , "-DskipTests" , "-Dmaven.test.skip.exec" , "-Dlicense.skip=true" ,
76
79
"-Drat.skip=true" , "-Dspotless.check.skip=true" };
@@ -80,7 +83,7 @@ private static boolean mavenBuild(String projectPath) {
80
83
81
84
public static boolean gradleBuild (String projectPath ) {
82
85
// Adjust Gradle command as needed
83
- String gradleWrapper = projectPath + "/gradlew" ;
86
+ String gradleWrapper = projectPath + File . separator + GRADLE_CMD ;
84
87
String [] gradleCommand = { gradleWrapper , "clean" , "compileJava" , "-p" , projectPath };
85
88
return buildWithTool (gradleCommand );
86
89
}
@@ -100,7 +103,7 @@ private static boolean buildProject(String projectPath, String build) {
100
103
}
101
104
else {
102
105
// Update command with a project path
103
- build = build .replace ("mvn" , "mvn -f " + projectPath );
106
+ build = build .replace (MAVEN_CMD , MAVEN_CMD + " -f " + projectPath );
104
107
Log .info ("Using custom build command: " + build );
105
108
String [] customBuildCommand = build .split (" " );
106
109
return buildWithTool (customBuildCommand );
@@ -139,7 +142,7 @@ public static boolean downloadLibraryDependencies(String projectPath) {
139
142
if (pomFile .exists ()) {
140
143
Log .info ("Found pom.xml in the project directory. Using Maven to download dependencies." );
141
144
String [] mavenCommand = {
142
- "mvn" , "--no-transfer-progress" , "-f" ,
145
+ MAVEN_CMD , "--no-transfer-progress" , "-f" ,
143
146
Paths .get (projectPath , "pom.xml" ).toString (),
144
147
"dependency:copy-dependencies" ,
145
148
"-DoutputDirectory=" + libDownloadPath .toString ()
0 commit comments