I am trying Gradle for the first time, and I have created a multi-project , to which I a have added a dependency from local Maven repository (only compiled files in a jar), which is developed in the same workspace. Right now, when I try to open declaration of classes in that jar i get source not found. I only found a method to attach a source jar to project, but no information on how can I reference a project as source for a jar.
“workspace” is not a term that has any defined meaning in the context of Gradle, so it is unclear what you mean.
Generally, using dependencies from mavenLocal() is a very bad idea, as it is broken by design in Maven already, and most often just makes your builds slow and flaky at best, silently broken at worst. Read more details about it at The case for mavenLocal().
Generally, how to get sources displayed also is not a Gradle question, but a question to your IDE vendor. But I guess when consuming the jar from Maven Local, you also have to have the source jar there to get the sources displayed automatically or otherwise need to attach the source directory in your IDE settings.
But what you are probably after anyway, is Composite Builds, assuming that other build is also a Gradle build and has a compatible version. Because then it simply is built when needed and you get the sources open in the IDE alongside automatically and can work on both projects simultaneously.
Other build is done in Maven, I am using/learning Gradle for the first time with a new project and I want to open relevant declarations from that dependency in their respective project ( I can do it with Eclipse build system by adding the project onto class path, but it does not work with Buildship).
Since workspace is not recognized by Gradle, can I just specify an absolute path to source directory for a dependency?
When you navigate from your Gradle project to the included classes from your Maven project, you will notice that these .class files cannot be changed. Your editor is read only.
If you want to reference the Maven Eclipse project (e.g. /demo) directly instead of the JAR (e.g. demo-1.0.0.jar) in your Gradle project, you have to manipulate the Eclipse Classpath in your build.gradle.
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
plugins {
id 'eclipse'
}
eclipse {
classpath {
file {
whenMerged {
it.entries = it.entries.collect {
it.path.endsWith('/demo-1.0.0.jar') ? new ProjectDependency('/demo') : it
}
}
}
}
}