diff --git a/lib/index.ts b/lib/index.ts index 47b3b83..2ce3763 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -273,14 +273,34 @@ async function getAllDeps(root, targetFile, options): Promise - task snykResolvedDepsJson { + task snykResolvedDepsJson { def onlyConf = project.hasProperty('configuration') ? configuration : null def depsToDict @@ -66,17 +66,26 @@ allprojects { everyProj -> def result = ['defaultProject': task.project.name, 'projects': projectsDict] if (!snykMergedDepsConfExecuted) { allprojects.each { proj -> + def snykConf = null if (proj.configurations.size() > 0) { - if (proj.configurations.findAll({ it.name == 'snykMergedDepsConf'}).size() == 0) { - def snykConf = proj.configurations.create('snykMergedDepsConf') + if (onlyConf != null) { + // We select one existing configuration, with its attributes. + snykConf = proj.configurations.getByName(onlyConf) + } else if (proj.configurations.findAll({ it.name == 'snykMergedDepsConf'}).size() == 0) { + // We create a new, "merged" configuration here. It has no attributes, which might be + // a problem for Android builds, where a resolution of a dependency "variant" + // is often dependent on configuration attributes (such as BuildType or Usage). + snykConf = proj.configurations.create('snykMergedDepsConf') proj.configurations .findAll({ it.name != 'snykMergedDepsConf' && (onlyConf == null || it.name == onlyConf) }) .each { snykConf.extendsFrom(it) } - projectsDict[proj.name] = [ - 'targetFile': findProject(proj.path).buildFile.toString(), - 'depDict': depsToDict(snykConf.resolvedConfiguration.firstLevelModuleDependencies) - ] } + } + if (snykConf != null) { + projectsDict[proj.name] = [ + 'targetFile': findProject(proj.path).buildFile.toString(), + 'depDict': depsToDict(snykConf.resolvedConfiguration.firstLevelModuleDependencies) + ] } else { projectsDict[proj.name] = [ 'targetFile': findProject(proj.path).buildFile.toString() diff --git a/test/manual/README.md b/test/manual/README.md new file mode 100644 index 0000000..a6938a3 --- /dev/null +++ b/test/manual/README.md @@ -0,0 +1,7 @@ +## Android build issues + +Since installing Android SDK is quite a hassle, there's no automated test for the Android Build Type problem +(https://snyksec.atlassian.net/browse/BST-528). + +Instead, please install Androd Studio or SDK on your own +and run `snyk test` on https://github.com/snyk-fixtures/android-cannot-auto-resolve to test