Skip to content

Commit

Permalink
fix(common-jvm): fix command to run Gradle tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed May 1, 2024
1 parent 32d2bfb commit 3081ff5
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/common-jvm/src/lib/builders/gradle-builder.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { hasGradleModule, hasGradleWrapper, hasGradleProject } from '../utils';
import { basename, resolve } from 'path';

export class GradleBuilder implements BuilderCore {
constructor(private commandAliases: BuilderCommandAliasMapper) { }
constructor(private commandAliases: BuilderCommandAliasMapper) {}

getBuildSystemType() {
return BuildSystem.GRADLE;
Expand All @@ -19,26 +19,39 @@ export class GradleBuilder implements BuilderCore {
return ignoreWrapper ? GRADLE_EXECUTABLE : GRADLE_WRAPPER_EXECUTABLE;
}

getCommand(alias: BuilderCommandAliasType, options: { cwd: string, ignoreWrapper?: boolean, runFromParentModule?: boolean }) {
getCommand(
alias: BuilderCommandAliasType,
options: {
cwd: string;
ignoreWrapper?: boolean;
runFromParentModule?: boolean;
}
) {
let additionalArgs = '';
let cwd = options.cwd;

if (!options.ignoreWrapper && !hasGradleWrapper(options.cwd) && !options.runFromParentModule) {
throw new Error(`⚠️ You chose not to use the Gradle wrapper from the parent module, but no wrapper was found in current child module`);
if (
!options.ignoreWrapper &&
!hasGradleWrapper(options.cwd) &&
!options.runFromParentModule
) {
throw new Error(
`⚠️ You chose not to use the Gradle wrapper from the parent module, but no wrapper was found in current child module`
);
}


let pathToModule: string[] = [];
if (options.runFromParentModule) {
let pathToModule:string[] = [];
const childModuleName = basename(cwd);
do {
const module = basename(cwd);
cwd = resolve(cwd, '..');
pathToModule = [module, ...pathToModule];
} while (!hasGradleModule(cwd, childModuleName));

additionalArgs = `-p ${pathToModule.join('/')} `;
additionalArgs = `${pathToModule.join(':')}`;
}

return { cwd, command: `${additionalArgs}${this.commandAliases[alias]}` };
return { cwd, command: `${additionalArgs}${pathToModule.length ? ':' : ''}${this.commandAliases[alias]}` };
}
}

0 comments on commit 3081ff5

Please sign in to comment.