1717 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1818 */
1919
20+ import * as path from 'path' ;
2021import * as vscode from 'vscode' ;
21- import { Uri } from "vscode" ;
22+ import { Uri , WorkspaceFolder } from "vscode" ;
2223import { Build } from './Build' ;
2324import { Maven } from './Maven' ;
2425import { Gradle } from './Gradle' ;
@@ -35,8 +36,21 @@ export class BuildSupport {
3536 return new Maven ( payaraInstance , workspace ) ;
3637 } else if ( Gradle . detect ( workspace ) ) {
3738 return new Gradle ( payaraInstance , workspace ) ;
38- } else {
39- throw new Error ( "Project build not supported for [" + uri . fsPath + "]." ) ;
39+ }
40+ // If build files not found at the workspace root, try the uri path itself.
41+ // This handles the case where the project is a subdirectory of the workspace.
42+ if ( uri . fsPath !== workspace . uri . fsPath ) {
43+ const projectWorkspace : WorkspaceFolder = {
44+ uri : uri ,
45+ name : path . basename ( uri . fsPath ) ,
46+ index : workspace . index // inherit the parent workspace index; only uri is used for file operations
47+ } ;
48+ if ( Maven . detect ( projectWorkspace ) ) {
49+ return new Maven ( payaraInstance , projectWorkspace ) ;
50+ } else if ( Gradle . detect ( projectWorkspace ) ) {
51+ return new Gradle ( payaraInstance , projectWorkspace ) ;
52+ }
4053 }
54+ throw new Error ( "Project build not supported for [" + uri . fsPath + "]." ) ;
4155 }
4256}
0 commit comments