@@ -28,6 +28,7 @@ export class GradleBuildReader implements BuildReader {
2828 private artifactId : string = '' ;
2929 private version : string = '' ;
3030 private finalName : string = '' ;
31+ private buildDirectory : string = '' ;
3132
3233 public constructor ( public workspaceFolder : WorkspaceFolder ) {
3334 this . parseBuild ( ) ;
@@ -45,6 +46,12 @@ export class GradleBuildReader implements BuildReader {
4546 let build : any = await g2js . parseFile ( buildPath ) ;
4647 reader . groupId = build . group ;
4748 reader . version = build . version ;
49+ reader . buildDirectory = reader . parseBuildDirectory ( buildPath ) ;
50+ }
51+
52+ let buildKtsPath = path . join ( this . workspaceFolder . uri . fsPath , 'build.gradle.kts' ) ;
53+ if ( reader . buildDirectory . length < 1 && fs . existsSync ( buildKtsPath ) ) {
54+ reader . buildDirectory = reader . parseBuildDirectory ( buildKtsPath ) ;
4855 }
4956
5057 if ( fs . existsSync ( settingsPath ) ) {
@@ -57,6 +64,23 @@ export class GradleBuildReader implements BuildReader {
5764 }
5865 }
5966
67+ private parseBuildDirectory ( gradleFilePath : string ) : string {
68+ try {
69+ const content = fs . readFileSync ( gradleFilePath , 'utf8' ) ;
70+ const fileMatch = content . match ( / b u i l d D i r \s * = \s * f i l e \( \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] \s * \) / ) ;
71+ if ( fileMatch ) {
72+ return fileMatch [ 1 ] ;
73+ }
74+ const stringMatch = content . match ( / b u i l d D i r \s * = \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / ) ;
75+ if ( stringMatch ) {
76+ return stringMatch [ 1 ] ;
77+ }
78+ } catch ( e ) {
79+ // ignore read errors and fall back to default
80+ }
81+ return '' ;
82+ }
83+
6084 public getGroupId ( ) : string {
6185 return this . groupId ;
6286 }
@@ -73,4 +97,8 @@ export class GradleBuildReader implements BuildReader {
7397 return this . finalName ;
7498 }
7599
100+ public getBuildDirectory ( ) : string {
101+ return this . buildDirectory ;
102+ }
103+
76104}
0 commit comments