hhrzc
hhrzc

Reputation: 2059

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:

How to correctly include the inner project?

Upvotes: 0

Views: 122

Answers (1)

George
George

Reputation: 2512

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.

Upvotes: 1

Related Questions