Skip to content

Commit

Permalink
feat: prefer build.gradle if kotlin also found
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Aug 13, 2020
1 parent 57d8d02 commit 6e806fb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib/find-files.ts
Expand Up @@ -256,6 +256,15 @@ function chooseBestManifest(
)[0];
return defaultManifest.path;
}
case 'gradle': {
debug(
'Encountered multiple gradle manifest files, defaulting to build.gradle',
);
const defaultManifest = files.filter((path) =>
['build.gradle'].includes(path.base),
)[0];
return defaultManifest.path;
}
default: {
return null;
}
Expand Down
15 changes: 15 additions & 0 deletions test/find-files.test.ts
Expand Up @@ -21,6 +21,7 @@ test('find all files in test fixture', async (t) => {
path.join(testFixture, 'golang', 'golang-gomodules', 'go.mod'),
path.join(testFixture, 'gradle', 'build.gradle'),
path.join(testFixture, 'gradle-kts', 'build.gradle.kts'),
path.join(testFixture, 'gradle-and-kotlin', 'build.gradle'),
path.join(testFixture, 'gradle-multiple', 'gradle/build.gradle'),
path.join(testFixture, 'gradle-multiple', 'gradle-another/build.gradle'),
path.join(testFixture, 'maven', 'pom.xml'),
Expand Down Expand Up @@ -54,6 +55,7 @@ test('find all files in test fixture ignoring node_modules', async (t) => {
path.join(testFixture, 'golang', 'golang-gomodules', 'go.mod'),
path.join(testFixture, 'gradle', 'build.gradle'),
path.join(testFixture, 'gradle-kts', 'build.gradle.kts'),
path.join(testFixture, 'gradle-and-kotlin', 'build.gradle'),
path.join(testFixture, 'gradle-multiple', 'gradle/build.gradle'),
path.join(testFixture, 'gradle-multiple', 'gradle-another/build.gradle'),
path.join(testFixture, 'maven', 'pom.xml'),
Expand Down Expand Up @@ -102,6 +104,19 @@ test('find package-lock.json file in test fixture (ignore package.json in the sa
t.same(result, expected, 'should return expected file');
});

test('find build.gradle file in test fixture (ignore build.gradle in the same folder)', async (t) => {
const buildGradle = path.join(testFixture, 'gradle-and-kotlin');

const result = await find(
buildGradle,
[],
['build.gradle.kts', 'build.gradle'],
1,
);
const expected = [path.join(buildGradle, 'build.gradle')];
t.same(result, expected, 'should return expected file');
});

test('find Gemfile.lock file in test fixture (ignore Gemfile in the same folder)', async (t) => {
const npmLockfilePath = path.join(testFixture, 'ruby');

Expand Down
Empty file.
33 changes: 33 additions & 0 deletions test/fixtures/find-files/gradle-and-kotlin/build.gradle.kts
@@ -0,0 +1,33 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
val kotlinVersion = "1.3.21"
id("org.jetbrains.kotlin.jvm") version kotlinVersion
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
}

version = "1.0.0-SNAPSHOT"

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

repositories {
mavenCentral()
}

dependencies {
// Removed Spring because too heavy
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testCompile("org.jetbrains.kotlin:kotlin-reflect") {
exclude(module = "junit")
}
}

0 comments on commit 6e806fb

Please sign in to comment.