Search code examples
javagradleintellij-idea

Dependency development in IntelliJ IDEA and gradle builder


There are two projects in gitlab:

  • project-a
  • project-a-dependency

In project-a, project-a-dependency is a dependency that is connected as:

implementation("my.space:project-a-dependency")

Currently, the development is carried out as follows:

  • Changes are being made to project-a-dependency
  • The assembly is done and sent to the nexus
  • I open the project-a project and pull down the new version of project-a-dependency

Question: is there any way to open two projects simultaneously in IntelliJ IDEA, change the dependency, rebuild the project and see all the changes? If the answer is yes, then how do I do it?

I tried the following: Project -> Project Structure -> Project Settings -> Modules -> [+] I added the project-a-dependency module and clicked the "apply" button.

Then I added it to build.gradle the line:

implementation project(':project-a-dependency')

I clicked the "Load gradle changes" button and got an error:

Project with path ':project-a' could not be found in root project 'project-a-dependency'.


Solution

  • If I understood you correctly and project-a-dependency is a standalone Gradle project you can achieve this with a composite build.

    A module dependency can be substituted by a dependency to a local fork of the sources of that module, if the module itself is built with Gradle.

    Add the dependency on project-a-dependency inside your settings.gradle.(kts) with the help of includeBuild() function. Included builds are added by location. This will allow you to work with your project-a-dependency as if it were just a module in your current project. Dependency substitution will be handled by Gradle for you.

    One thing to note is that since your dependency is local it will have to be compiled instead of just being an available binary

    More info: https://docs.gradle.org/current/userguide/composite_builds.html#defining_composite_builds