@@ -42,8 +42,6 @@ export class Gradle implements Build {
4242
4343 private microPluginReader : GradleMicroPluginReader | undefined ;
4444
45- private cachedBuildDir : string | undefined ;
46-
4745 constructor ( public payaraInstance : PayaraInstance | null , public workspaceFolder : WorkspaceFolder ) {
4846 this . readBuildConfig ( ) ;
4947 }
@@ -236,37 +234,15 @@ export class Gradle implements Build {
236234 return gradleExecStr ;
237235 }
238236
239- public detectBuildDir ( ) : string {
240- if ( this . cachedBuildDir !== undefined ) {
241- return this . cachedBuildDir ;
242- }
243- const gradleFiles = [ 'build.gradle' , 'build.gradle.kts' ] ;
244- for ( const gradleFile of gradleFiles ) {
245- const filePath = path . join ( this . workspaceFolder . uri . fsPath , gradleFile ) ;
246- if ( fs . existsSync ( filePath ) ) {
247- try {
248- const content = fs . readFileSync ( filePath , 'utf8' ) ;
249- const fileMatch = content . match ( / b u i l d D i r \s * = \s * f i l e \( \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] \s * \) / ) ;
250- if ( fileMatch ) {
251- this . cachedBuildDir = fileMatch [ 1 ] ;
252- return this . cachedBuildDir ;
253- }
254- const stringMatch = content . match ( / b u i l d D i r \s * = \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / ) ;
255- if ( stringMatch ) {
256- this . cachedBuildDir = stringMatch [ 1 ] ;
257- return this . cachedBuildDir ;
258- }
259- } catch ( e ) {
260- // ignore read errors and fall back to default
261- }
237+ public getBuildDir ( ) : string {
238+ let buildDirValue = 'build' ;
239+ if ( this . buildReader instanceof GradleBuildReader ) {
240+ let customDir = this . buildReader . getBuildDirectory ( ) ;
241+ if ( customDir . length > 0 ) {
242+ buildDirValue = customDir ;
262243 }
263244 }
264- this . cachedBuildDir = 'build' ;
265- return this . cachedBuildDir ;
266- }
267-
268- public getBuildDir ( ) : string {
269- let buildDir = path . join ( this . workspaceFolder . uri . fsPath , this . detectBuildDir ( ) , 'libs' ) ;
245+ let buildDir = path . resolve ( this . workspaceFolder . uri . fsPath , buildDirValue , 'libs' ) ;
270246 if ( ! fs . existsSync ( buildDir ) ) {
271247 throw Error ( "no build dir found: " + buildDir ) ;
272248 }
0 commit comments