‘config.each { file -> … }’ will give you the cached files. (If you need more information than just the file, check out the ‘Configuration#getIncoming()’ and ‘Configuration#getResolvedConfiguration()’ APIs.) I’m not aware of a public API that tells which repository a module originates from.
Gradle has a list of repositories and you define a list of dependencies. Then it goes through the repos and checks if the dependency can be fetched. If the first repo fails it tries the next only complaining if it cannot be found at any place you specified. You could simulate Gradle’s fetching process. Create a ‘listofRepositories’ which you then add inside the repositories{}. You can then go through this list of repositories and find out for every dependency which repo can it be fetched from.
project.configurations.each { config ->
config.allDependencies.each { d ->
// d can be of type ProjectDependency, ExternalModuleDependency, SelfResolvingDependency, etc.
// ExternalModuleDependency comes from a repository
// try fetching the dependency by going through all repos. ExternalModuleDependency offers the necessary info (group, name, version)
// use config.fileCollection(d) to get a path to the jar stored on disk
}
}
I wouldn’t do something like that but I don’t know what you are doing so it might be really important.
config.allDependencies.each only gives me the declared dependencies but NOT the transitive dependencies.
Using fileCollection resolves all files including transitive jar.
Is there a trick to get also the transitive dependencies and then print out group:name:version? (again I don’t want to extract this information from the files but would like to query the dependency objects)
@Dieter I had been writing my code this way, but I was hoping there was a better way to check!
I also looked at “getIncoming” and “resolvedConfigurations” but When I call getIncoming I get an empty list bac, and I run into a NullPointer when I try to call resolvedConfigurations (entirely possible I’m calling it at a bad time in the build?). At what point in my gradle script can I call these accessors?
In case you’re curious, here’s the (massive) stack trace for the NPE:
12:28:45.875 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
12:28:45.875 [ERROR] [org.gradle.BuildExceptionReporter]
12:28:45.875 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
12:28:45.876 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':app:compileDebugJava'.
12:28:45.876 [ERROR] [org.gradle.BuildExceptionReporter] > Could not resolve all dependencies for configuration ':app:_debugApk'.
12:28:45.877 [ERROR] [org.gradle.BuildExceptionReporter]
> java.lang.NullPointerException (no error message)
12:28:45.879 [ERROR] [org.gradle.BuildExceptionReporter]
12:28:45.880 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
12:28:45.882 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJava'.
12:28:45.883 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
12:28:45.884 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
12:28:45.884 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
12:28:45.885 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
12:28:45.886 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
12:28:45.886 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
12:28:45.886 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
12:28:45.887 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
12:28:45.887 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
12:28:45.887 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
12:28:45.888 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
12:28:45.888 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
12:28:45.888 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
12:28:45.888 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33)
12:28:45.889 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.internal.Factories$1.create(Factories.java:22)
12:28:45.889 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)
12:28:45.889 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:266)
12:28:45.890 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:135)
12:28:45.890 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:95)
12:28:45.890 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
12:28:45.890 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
12:28:45.891 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
12:28:45.891 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
12:28:45.891 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
12:28:45.892 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
12:28:45.892 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
12:28:45.892 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
12:28:45.892 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
12:28:45.893 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
12:28:45.893 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
12:28:45.893 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
12:28:45.893 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
12:28:45.894 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
12:28:45.894 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
12:28:45.894 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
12:28:45.894 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
12:28:45.895 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
12:28:45.895 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
12:28:45.895 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
12:28:45.895 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
12:28:45.896 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
12:28:45.896 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
12:28:45.896 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
12:28:45.897 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
12:28:45.897 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.Main.doAction(Main.java:46)
12:28:45.897 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
12:28:45.897 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.Main.main(Main.java:37)
12:28:45.898 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
12:28:45.898 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
12:28:45.898 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
12:28:45.898 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':app:_debugApk'.
12:28:45.899 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.wrapException(ErrorHandlingArtifactDependencyResolver.java:57)
12:28:45.899 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.access$000(ErrorHandlingArtifactDependencyResolver.java:34)
12:28:45.899 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$ErrorHandlingResolvedConfiguration.getFiles(ErrorHandlingArtifactDependencyResolver.java:186)
12:28:45.899 [ERROR] [org.gradle.BuildExceptionReporter]
at org.foo.MyPlugin$_apply_closure1_closure3_closure5_closure6.doCall(MyPlugin.groovy:96)
12:28:45.900 [ERROR] [org.gradle.BuildExceptionReporter]
at org.foo.MyPlugin$_apply_closure1_closure3_closure5.doCall(MyPlugin.groovy:86)
12:28:45.900 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:502)
12:28:45.900 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:483)
12:28:45.901 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
12:28:45.901 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
12:28:45.901 [ERROR] [org.gradle.BuildExceptionReporter]
... 49 more
12:28:45.901 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.NullPointerException
12:28:45.902 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.util.CollectionUtils.filter(CollectionUtils.java:86)
12:28:45.902 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.util.CollectionUtils.filter(CollectionUtils.java:59)
12:28:45.902 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver$SelfResolvingFilesProvider.getFiles(SelfResolvingDependencyResolver.java:61)
12:28:45.902 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver$FilesAggregatingResolvedConfiguration.getFiles(SelfResolvingDependencyResolver.java:80)
12:28:45.903 [ERROR] [org.gradle.BuildExceptionReporter]
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$ErrorHandlingResolvedConfiguration.getFiles(ErrorHandlingArtifactDependencyResolver.java:184)
@Carsten, I hope there is a better way (because I will be doing the same thing!), but as it is, I plan to access those .aar files as Peter suggested, unzip them, and then you can access classes.jar which are the compiled classes for that .aar, and then there’s a lib directory in the unzipped .aar with the transitive jars.