Skip to content

Commit

Permalink
fix: subproject with same name as root (#222)
Browse files Browse the repository at this point in the history
In multi-module projects filter subprojects based on unique the path not name
  • Loading branch information
ola magdziarek authored Sep 2, 2022
1 parent 79a8a08 commit 3ea5ec1
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/init.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ allprojects { currProj ->
def allSubProjectNames = []
def seenSubprojects = [:]
allprojects
.findAll({ it.name != defaultProjectName })
.findAll({ it.path != task.project.path })
.each({
def projKey = it.name
if (seenSubprojects.get(projKey)) {
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/subproject-with-same-name-as-root/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Multi-module project with a nested subproject with the same name as root

The following dep-tree was generated using the command: `./gradlew dependencies`

```s
+--- com.google.guava:guava:30.1.1-jre
| +--- com.google.guava:failureaccess:1.0.1
| +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
| +--- com.google.code.findbugs:jsr305:3.0.2
| +--- org.checkerframework:checker-qual:3.8.0
| +--- com.google.errorprone:error_prone_annotations:2.5.1
| \--- com.google.j2objc:j2objc-annotations:1.3
\--- joda-time:joda-time:2.2
```
12 changes: 12 additions & 0 deletions test/fixtures/subproject-with-same-name-as-root/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id 'application'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'com.google.guava:guava:30.1.1-jre'
implementation "joda-time:joda-time:2.2"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id 'application'
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation "org.apache.struts:struts2-spring-plugin:2.3.1"
}
11 changes: 11 additions & 0 deletions test/fixtures/subproject-with-same-name-as-root/lib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
compile 'org.apache.commons:commons-lang3:3.12.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'subproject-with-same-name-as-root'
include ':lib', ':greeter', ':greeter:subproject-with-same-name-as-root'
40 changes: 40 additions & 0 deletions test/system/multi-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ test('multi-project: use full path for subprojects with the same name', async ()
]);
});

test('multi-project: do not exclude subprojects with the same name as root', async () => {
const result = await inspect(
'.',
path.join(fixtureDir('subproject-with-same-name-as-root'), 'build.gradle'),
);
expect(result.plugin.meta!.allSubProjectNames).toEqual([
'greeter',
'lib',
'subproject-with-same-name-as-root',
]);
});

test('multi-project: use flat naming when subprojects have different names', async () => {
const result = await inspect(
'.',
Expand Down Expand Up @@ -466,3 +478,31 @@ test('multi-project: correct deps when subprojects have different names', async
expect(greeterLibGraph.length).toBe(1);
expect(greeterLibGraph).toEqual(['commons-io:commons-io@2.11.0']);
});

test('multi-project: correct deps for subprojects with the same name as root', async () => {
const result = await inspect(
'.',
path.join(fixtureDir('subproject-with-same-name-as-root'), 'build.gradle'),
{ allSubProjects: true },
);

const projectDeps = {};
for (const p of result.scannedProjects) {
projectDeps[p.meta.projectName] = p.depGraph
.getDepPkgs()
.map((d) => `${d.name}@${d.version}`);
}

const rootGraph = projectDeps['subproject-with-same-name-as-root'];
expect(rootGraph.length).toBe(8);
expect(rootGraph).toContain('com.google.guava:guava@30.1.1-jre');

const greeterSubprojGraph =
projectDeps[
'subproject-with-same-name-as-root/greeter/subproject-with-same-name-as-root'
];
expect(greeterSubprojGraph.length).toBe(21);
expect(greeterSubprojGraph).toContain(
'org.apache.struts:struts2-spring-plugin@2.3.1',
);
});

0 comments on commit 3ea5ec1

Please sign in to comment.