Gradle sub project dependency - java

I have a java project, composed of 2 sub project (A , B)
A has its own gradle file with some dependencies
B has its own gradle file with dependecy on project A using (implementation project(':A')
Would this mean that libraries that are part of project 'A' gradle file, need not in project 'B' gradle file ?
Or would I still have to defines them in project B
Theoretical question

Related

Add a non Gradle Project to a Gradle Multiproject as Module in Intellij

Project A is a Gradle multi project with the sub projects b and c.
Project X is a non Gradle project. The sub projects depend on (compiled) project X.
The Project X jar is included as file tree dependency in the
build.gradle of the sub projects:
implementation fileTree(dir: project.projectDir.path + '/lib/', include: ['X.jar])
As IDE we are using Intellij. We want to have project A and X in the same workspace and we want to have changes made in project X to be reflected on the classpath of Project A.
We tried to add project X to A,b,c in the Module Settings in Intellij as dependency without success.
Is there a way to achive the described scenario in Intellij without migrating project X to gradle?

Intellij : import project as library for another project

I am developing a project A (Java Maven) which uses a library B (a JAR file)
I have the source code of library B, and I want to change code in project B, while it's used as library for project A.
Is that possible in Intellij to replace a JAR library by its source code ?
I'd configure a multi-module Maven project with the parent aggregate pom.xml and 2 sub-modules: for the app and for the library with their own pom.xml files.
Define a dependency on the lib module for the app module. IDE will resolve such dependencies via the sources and you will see the changes in the project instantly without the need to compile. Refactorings will also work across the modules so that you can rename a method from the usage in the app and it will automatically rename it in the lib.

Eclipse - Project Referencing another Project instead of .jar File

I have a Java project in eclipse:
Project A contains an Ivy dependency on Project B.
Locally, I checked out and made changes to Project B. I then wanted to test the new functionality from Project B in Project A, so I added Project B as a project dependency of Project A by adding it to the Java Build Path (Java Build Path->Projects->Add...).
I no longer wish to have that dependency on Project A, but simply removing it from the Projects Build Path hasn't worked. With that dependency removed, I would expect that any references to the new local code would result in a syntax error, since those changes have not been incorporated into a new artifact for Ivy to pull in.
How can I remove any references to Project B from Project A? I've tried deleting both projects and re-checking them out and that did not work.
The way to resolve this issue is to:
Close Project B in eclipse.
On Project A run Project-Clean
Resolve Ivy dependencies on Project A
Now the dependencies from Project B should use the Ivy artifact rather than the local changes.

Eclipse Oxygen project linking to class files instead of source files

I have 3 Java projects in my workspace in Eclipse (Oxygen). The projects are A, B and Utils. The Utils project is used by both A and B. If I go into the Java Build Path for either of those projects, I can see the Utils project listed under the Projects tab option (required projects on the build path).
If I hold ctrl key and hover over functions, classes etc. that belong to Utils project from a source file in project A, then the links take me to the relevant source file in Utils project. If I do the same in project B, it always attempts to open the class file, not the source.
Is there something else I need to configure in project B to link the source files in Utils?
Make sure, in the Java Build Path of project B, in the tab Libraries, the bin/class folder of the Utils project is not added as a class folder. The dependency to the Utils project should be defined in the Projects tab only.

importing project in Eclipse

Hello I am new to Eclipse (and I am a novice in Java): I am creating a project which should make use of some classes from another project. Do I have to export necessarily this last project as JAR file and add in my project? Are there other alternatives?
There are several alternatives:
If project A depends on project B, and both projects are in the same Eclipse workspace, you can just project B to project A's build path (project properties / build path / project). This has the nice advantage that it will (optionally) automatically pull in project B's JARs, plus updates to B will be used automatically by A, and you can debug into B's code (even using hot code replace).
If A and B are fairly separate, just make B into a JAR (or several ones), then add these to A's build path.
If you have the source of those class files you can just link that source
Or add the other project as a dependent project.
Or create a jar of those classes and add that in lib.

Categories