diff --git a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/SimpleProjectFunctionalTest.java b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/SimpleProjectFunctionalTest.java index 75f04e8e..3c4787c9 100644 --- a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/SimpleProjectFunctionalTest.java +++ b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/SimpleProjectFunctionalTest.java @@ -108,8 +108,12 @@ public void ensureAlignmentFileCreated() throws IOException, URISyntaxException, }); }); - //verify that dummy.gradle now includes the gme-repos.gradle injection - final File extraGradleFile = projectRoot.toPath().resolve("gradle/dummy.gradle").toFile(); + //verify that dummy.gradle and another.gradle now includes the gme-repos.gradle injection + File extraGradleFile = projectRoot.toPath().resolve("gradle/dummy.gradle").toFile(); + assertThat(extraGradleFile).exists(); + assertThat(FileUtils.readLines(extraGradleFile, Charset.defaultCharset())) + .filteredOn(l -> l.trim().equals(AlignmentTask.APPLY_GME_REPOS)).hasSize(1); + extraGradleFile = projectRoot.toPath().resolve("gradle/subdirectory/another.gradle").toFile(); assertThat(extraGradleFile).exists(); assertThat(FileUtils.readLines(extraGradleFile, Charset.defaultCharset())) .filteredOn(l -> l.trim().equals(AlignmentTask.APPLY_GME_REPOS)).hasSize(1); diff --git a/analyzer/src/functTest/resources/simple-project/gradle/subdirectory/another.gradle b/analyzer/src/functTest/resources/simple-project/gradle/subdirectory/another.gradle new file mode 100644 index 00000000..60fbc7a5 --- /dev/null +++ b/analyzer/src/functTest/resources/simple-project/gradle/subdirectory/another.gradle @@ -0,0 +1,9 @@ +// this is used in order to test that gme-repos.gradle gets injected +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'de.thetaphi:forbiddenapis:2.5' + } +} diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java index 9c348a42..dc3228ed 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java @@ -128,8 +128,11 @@ public class AlignmentTask extends DefaultTask { /** * The groovy code to apply the {@link AlignmentTask#GME_REPOS gme-repos.gradle} build script. */ - public static final String APPLY_GME_REPOS = "buildscript { apply from: new File(buildscript.getSourceFile().getParentFile(), \"" - + GME_REPOS + "\"), to: buildscript }"; + // Can't use the path of the build script as it may be in a subdirectory. Further it may be included from via + // a composite build which alters the root path. + public static final String APPLY_GME_REPOS = "buildscript { apply from: new File((gradle.getParent() == null ? gradle : gradle.getParent()).startParameter.getCurrentDir(), \"gradle/" + + GME_REPOS + + "\"), to: buildscript }"; /** * The task name {@code generateAlignmentMetadata}. */