Add Gradle dependent projects to quickly reflect changes in dependent project
I have 3 gradle java projects. One project is dependent on two others. I want to immediately reflect changes in dependent projects into my main project.
I tried adding a project using File->Project Structure-> Libraries-> + -> Java -> Add dependent project build/classes/java/main. But it vanishes for no reason or just does not work.
I also tried File->Project Structure->Modules->Dependencies-> + -> Java/Jar But it gives warning there itself "The module is imported from Gradle. Any changes made in its configuration may be lost after reimporting.
I did not use Eclipse before, but I know its very easy in eclipse. This is the first time I am using gradle builds. With our enterprise wide setup, I dont see the jars in the ~/./gradle/cache.
请先登录再写评论。
Import your Gradle projects as IntelliJ IDEA modules using Project Structure | Modules | + | Import Module. Then add one module to the dependencies of the other module.
A much better solution would be to use Gradle composite projects by creating a root build.gradle file that will define the dependencies between your projects and import this root file in IntelliJ IDEA.
See these links:
https://blog.jetbrains.com/idea/2016/10/intellij-idea-2016-3-eap-gradle-composite-builds-and-android-studio-2-2/
https://docs.gradle.org/3.1/release-notes.html#composite-builds
https://www.jetbrains.com/help/idea/work-with-gradle-projects.html#gradle_composite_build
https://blog.jetbrains.com/idea/2017/03/webinar-recording-composite-builds-with-gradle/
Thanks. While importing, I selected "Create New Module from Existing Sources" rather than "Import module from external model. But I dont see changes in dependent module reflecting. Added the dependency. Is this correct ? Attached image.
Should I create totally new project and add all 3 projects as modules and then create dependency ?
You should import from external model. Yes, it makes sense to create a new empty project and import 3 modules from Gradle into it.
Once again, a much better solution would be to use the composite build with the root build.gradle file. This way your project will work the same from the command line and from IntelliJ IDEA and IDE will be able to configure all the dependencies automatically.
Thanks. I created brand new gradle project and added modules. Added dependency. But still not working. Sorry, I am newbie to Gradle, so not able to quickly try your third option. Also the projects are written by someone else for the environment, so have limitations compared to new projects.
Here is the screenshot of new project and module dependency.
Please share a sample project at https://uploads.jetbrains.com and describe what exactly doesn't work.
Will the code remain confidential ? its company property. Also, some dependencies are pulled from internal nexus. I am sure you will not be able to build the projects.
In the previous attached image, apc2vachcommon is a depenency on ach-core. Change in apc2vachcommon should be immediately visible (in auto-suggestions) on ach-core. Otherwise I need to upload apc2vachcommon to nexus and get it back using gradle refresh, every time I lose 5 minutes as its slow.
Thanks
That is what Gradle composite builds are for. You should learn how to use them even outside of the IDE, then just import the composite build in the IDE.
Hi Serge - I worked with you last week. I tried all the ways to create a composite build in Intellij. I have uploaded to projects with this id Upload id: 2021_06_02_LR3F2CuLwaZSrNsn (files: apc2vachcommon.tar, apc2vachcore.tar).
Please note that apc2vachcommon is a dependency on apc2vachcore. Since the config needs many jars from our internal repository, you will not be able to build, but may find issue. Here is the snapshot, in which It shows I have done as much as possible. Again, my intent is to immediately reflect changes in apc2vachcommon in master project apc2vachcore. and also debug using .java and not .class. Help would be highly appreciated.
I cannot check the uploaded project b/c I cannot import it into the IDE - import fails. But for the IDE to use module dependency instaed of the local jar library for the project configured as a Composite and provided you have the dependency on in declared as
So this apc2vachcommon project must have the
group 'com.tsys.enterprise'
the
version 'tsysap-272'
and have the
apc2vachcommon
as a project name.
Thanks, will try.
Thanks. Yes, there was an issue with group names. The two projects I attached worked ! Thank you ! But I have third runnable project which is dependent on these 2 projects. Sorry this could be gradle question, but In the runnable project (3rd one), I am able to include only apc2vachcore but not apc2vachcommon. Is there anything I have to follow when there is chained dependency ?
I tried changing settings.gradle (includeBuild etc) and build.gradle several ways.
Thanks again.
Please ignore my question ! It was some dumb mistake. Huge Thank you !