how do I get gradle to depend on a local project t...
# announcements
t
how do I get gradle to depend on a local project that isn't in a subdirectory of the current project? I keep getting the error "could not be found in root project of...."
I'd pay good money for a build tool that I didn't spend more than 20% of the time on the project fighting. Why are they always so complicated and so horribly documented?
h
I recommend not to get angry and accept that adcanced Tools cant be mastered over night, looks like you don't know too much about gradle tbh... The documentation of gradle is first class, but even to me, it's not clear what you try to achieve. Totally guessing here, possible that you want*composite build* ?
Composite builds include other local, Independent builds as if they were Part of the other build.
Side note, If this is what you need, this is an advanced use case and i don't think any other build tool than gradle has this feature, although i don't know for certain. If composite builds is not what you need, let us know and we try to help further
Side note 2, i don't think this is connected to kotlin at all...
t
thanks for the advice. But it's about as useful as tits on a bull. I've been scouring the "first class" documentation for days. No help on on to actually depend on a task. Just how to depend on another project. There are some things like project().tatks, but that doesn't exist inside a dependency clause.
if this is "advanced" then that's kind of pathetic. People have been writing self-generating code since computers began. This is the standard way to do it.
h
Omg honestly, you haven't understood even the naked basics of gradle, so whats pathetic here is your attitude. Dependencies (what you mean) is "cobfigurations" in gradle, with what you can do things like depend on a binary artifact. There's no such thing as task dependencies here, because a binary file for example doesn't define tasks, it's just a file. Again, you are not able to explain properly what you want to achieve but i suspect that you want composite build. But thats something you would use for development only, for example for efficient microservice development because of many Independent repositories... If you want to use a binary file from whoknowswhere and use it as a compile depdendency you can define a the folder as a flat file artifact repository, reference the file with its filename as Implementation/compile/api dependency (cobfiguration...) And fine. If the given artifact you want to depend on is produced in a special way then there are better ways to do that, but how could one know what you want to achieve.
👍 1
If your referenced folder contains a subproject of your project, things are easier, you can include the subproject in the likes of https://discuss.gradle.org/t/multi-module-project-with-relative-paths-to-sub-projects/4581 . You can than depend on artifacts produced by the build of the subproject like in this example https://docs.gradle.org/current/userguide/declaring_dependencies.html#sec:resolvable-consumable-configs . If that is not sufficient for you (for whatever reasons, my imagination is limited) you can always resort to file dependency directly. Give a hint if you need further help
t
I have standard "application" project. Call it Project A. It's "run" task generates kotlin files. I need project B not just to depend on project A, but to execute project A's run task. This should be simple as dirt....
it's easy to get project B to depend on project A. that's trivial, and that's all that link you sent explains. I already have that.
Or have project A's build.gradle generate the code itself by first compiling, then running then compiling again.. which likely seems more complex. but whatever if that's easier for gradle to cope with.
I'm not depending on the artifact of a "build". I'm depending on a artifact of a execution of a build.
h
Okay, so you have source code generation, now we are moving forward. I make it short: If you do code Generation, it's easier to do that in the project you want to compile the source code as well. So only one project. Lets assume the code is generated by writing text to a kt file. You need three things then: a task that produces the code, a task dependency and a sourceset where to put the sources... Lets call the Task generateSources and you need compileKotlin.dependsOn(generateSources). Third, you need a sources folder in your build folder (because i assume you don't want the code in your src folder as it is checked in), and Register this folder as sources folder. Here https://stackoverflow.com/questions/28345705/how-can-i-add-a-generated-source-folder-to-my-source-path-in-gradle is an answer how to do that. You should be done after doing that. The source code Generator could be written inline in the generateSources task, as you can write groovy or kotlin inline. If that's not appropriate for you, i would simply place your code Generator in the buildSrc project... All depending on what you code generator inputs are and what it should generate