I'm new to gradle and still trying to understand it, so please assume I have no idea what I'm talking about if you give an answer. :) I'm using gradle 7.3.3.
I've got an Android app project that has the standard app
module. In my app
module is a class named com.inadaydevelopment.herdboss.DatabaseConfigUtil
and I want to be able to run DatabaseConfigUtil.main()
and it needs to have all of the classes from app
in the classpath.
I've created a second module named libdbconfig
which is just a Java Library module so that I can create a JavaExec task which will call DatabaseConfigUtil.main()
and make sure that all of the classes from app
are in the classpath.
My libdbconfig/build.gradle
file looks like this:
plugins {
id 'java'
}
dependencies {
implementation project(":app")
}
task dbconfig(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = "com.inadaydevelopment.herdboss.DatabaseConfigUtil"
}
I sync AndroidStudio with my build.gradle changes and then try to run the libdbconfig:dbconfig
task and get the error:
* What went wrong:
Could not determine the dependencies of task ':libdbconfig:dbconfig'.
> Could not resolve all task dependencies for configuration ':libdbconfig:runtimeClasspath'.
> Could not resolve project :app.
I thought I understand how to declare a dependency on another sub-project and whenever I look at examples (Example 11. Declaring project dependencies it looks like I'm doing it right.
If I change my dependencies to remove the word "implementation" then the gradle config doesn't throw an error, but I don't understand that at all since it doesn't attach the dependency to a configuration (like "implementation").
dependencies {
project(":app")
}
When I do that, the gradle task will start, but will ultimately fail because the classes from the app
module are not in the classpath and so it can't find the class to run:
> Task :libdbconfig:dbconfig FAILED
Error: Could not find or load main class com.inadaydevelopment.herdboss.DatabaseConfigUtil
Caused by: java.lang.ClassNotFoundException: com.inadaydevelopment.herdboss.DatabaseConfigUtil
Any help is appreciated. gradle has been voodoo to me for a long time and I'm trying to figure it out. I went through a udacity course on how to use it and I thought I had a much better understanding of it, but some of the basic things I thought I understood aren't working.
from gradle cannot resolve dependecy project(":app") from other sub-project
No comments:
Post a Comment