'How to include inner project with gradle builder
I try to follow some tutorial and create my own Gradle task and I need to create the inner project for it. I created a new directory in my main folder with the same structure:
mainproject
--> src
------>build.gradle
------>main
----------->java
--------------->MainJavaClass.java
----->innerproject
---------> src
-------------> build.gradle
------------->main
----------------->java
-------------------->InnerJavaClass.java
But in this case I can't use any dependencies in innerproject and InnerJavaClass.java, and even can't execute psvm method from the InnerJavaClass.
The error:
- Could not find or load main class
InnerJavaClass.java
How to correctly include the inner project?
Solution 1:[1]
I think you need to use Multi module projects. here is a simple example.
Project A (main) and includes Project B and Project C.
Project A setting.gradle
rootProject.name = 'A'
include ':B', ':C'
And Project A build.gradle dependency section
implementation project(':B')
implementation project(':C')
Project B and Project C are the same with no extra information and here is an example
Project B setting.gradle
rootProject.name = 'B'
And defualt build.gradle with no extra information required.
The structure should be look something like the following
A
--> build.gradle
--> setting.gradle
--> src
------>main
----------->java
--------------->MainJavaClass.java
-->B
--> build.gradle (for B)
--> setting.gradle (for B)
--> src
------>main
----------->java
--------------->MainJavaClass.java (for B)
-->C
--> build.gradle (for C)
--> setting.gradle (for C)
--> src
------>main
----------->java
--------------->MainJavaClass.java (for C)
This way you can use the dependencies and once you build A project both B and C would be build as included dependency.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | George |
