#Converting Maven project to Gradle in IntelliJ

1 messages · Page 1 of 1 (latest)

pearl pond
#

Right now I have a simple Maven project I guess and I want to convert it to Gradle for the multi-module thingy.

gentle star
#

So did you do the steps I told you?

pearl pond
#

Yes, download the Gradle and then put it on the C:\Gradle

#

Should I ran the gradle init inside the project that I want to be converted?

gentle star
#

You use Windows tight?

pearl pond
#

Yes.

gentle star
#

did you put create a new environment variable?

pearl pond
#

I don't know what that is?

gentle star
#

In File Explorer right-click on the This PC (or Computer) icon, then click Properties → Advanced System Settings → Environmental Variables.

Under System Variables select Path, then click Edit. Add an entry for C:\Gradle\gradle-7.2\bin. Click OK to save.

Alternatively, you could also add the environment variable GRADLE_HOME and point this to the unzipped distribution. Instead of adding a specific version of Gradle to your Path, you can add %GRADLE_HOME%/bin to your Path. When upgrading to a different version of Gradle, just change the GRADLE_HOME environment variable.

#

It’s a way to make shortcut names and variables for your system/pc

pearl pond
#

Okay, I've done the environment variables.

gentle star
#

Then if you go into IntelliJ

#

Open up a new terminal instance

#

A run gradle -v

#

Does it say anything?

pearl pond
#

gradle not recognized

gentle star
#

Then you did it incorrectly

pearl pond
#

Do I need to restart the IntelliJ?

gentle star
#

Yeah

#

Good point

pearl pond
#

Yeah it says something now.

#
------------------------------------------------------------
Gradle 7.2
------------------------------------------------------------

Build time:   2021-08-17 09:59:03 UTC
Revision:     a773786b58bb28710e3dc96c4d1a7063628952ad

Kotlin:       1.5.21
Groovy:       3.0.8
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.11 (AdoptOpenJDK 11.0.11+9)
OS:           Windows 10 10.0 amd64
gentle star
#

Aye

#

Ok run gradle init now

pearl pond
#

aight

#

Found a Maven build. Generate a Gradle build from this? (default: yes) [yes, no]

gentle star
#

Yes

pearl pond
#

oh god im scared

gentle star
#

Nonono

#

Why

pearl pond
#

it wouldn't be fun if there is something goes wrong xd

#

but i've done it

#

it says build successful

gentle star
#

You have it on GitHub?

#

If so then you can revert back

pearl pond
gentle star
#

Oo yeah

pearl pond
#

yes i have it on github before converting it to gradle

gentle star
#

You can delete pom.xml

#

And restart IntelliJ by invalidating caches also

#

Just to make sure no issues

pearl pond
#

alright

#

might take a while

#

I think it's completed

gentle star
#

Oh ok

pearl pond
#

No errors on the code or anything

gentle star
#

You know the tab where you used to have maven tasks

pearl pond
#

yeah it's gone now

gentle star
#

Does a gradle one exist equivalently?

pearl pond
#

how do i add it back

#

no, the tab is gone

gentle star
#

If not right click the build.gradle and load it

#

Or if u got some option called load gradle script

pearl pond
#

how do u load it?

gentle star
#

Wait can u send screenshots of ur screen when right clicked build.gradle?

pearl pond
gentle star
#

Send a screenie of entire monitor maybe xD

pearl pond
#

oh okay, my bad xd

#

pardon my active windows 👀

gentle star
#

Hmm yeah

#

Try removing .idea

#

And restart and invalidate caches again @pearl pond

#

Sry for being absent a bit

pearl pond
#

all good

gentle star
#

but yeah remove the .idea folder

#

and restart again

#

once u done that

#

do u get prompted with anything regarding gradle?

pearl pond
#

yes

#

i have the tab now

gentle star
#

ok good

#

so when u build

#

you generally want to use the task clean

#

followed by build

pearl pond
#

clean and then build?

gentle star
#

yeah

#

wait

#

are you shading stuff?

pearl pond
#

yup, my libs

gentle star
#

oh

#

okay

pearl pond
#

Works perfectly tho, no errors.

gentle star
#

send ur build.gradle

pearl pond
#

wait, i don't see any clean on the tasks

gentle star
#

it should be under the group build just like the task build

pearl pond
#

oh i see

gentle star
#

use this instea

#

so paste it in

#

and reload gradle project

#

then instead of running clean then build

run clean then shadowJar instead

pearl pond
#

got it

#

Just to let you know that BackpackWrapper is actually the modules/libs that I want to be added to the project.

#

Right now I have it on different projects because I don't know how to merge it.

gentle star
#

oh okay

#

well

#

anyways

#

if u run

#

clean

#

then shadowJar

#

and check the output jar

#

does it contain what u wantd

pearl pond
#

what's the path to the output?

gentle star
#

build/libs

pearl pond
#

okay

#

and yes it has what i want

#

in fact im gonna test it on the server first

#

it's running perfectly fine

#

there are some errors, but it's just from the code

gentle star
#

Oh okay

#

btw

#

@pearl pond

#

check out an example of using multi project structure to mess with nms

pearl pond
#

can't you have the "main" without the modules?

gentle star
#

you can

pearl pond
gentle star
#

but then you wont be able to depend on two versions of the same project/dependency simultaneously

pearl pond
#

anyway

#

how do you create the module?

gentle star
#

create a folder

#

lets say its named v1_8_r3

#

then you'd have in settings.gradle

#

include ':v1_8_r3'

#

and then in v1_8_r3 you'd have a src folder and a build.gradle file

#

check out that

#

if you have any questions then ask 😄

pearl pond
#

alright, let's see

#

How can I include an interface from the main code?

#

nvm, i got it

#

but, how do u add build tools spigot?

#

woops nvm, i got it again

#

it's much more easier on gradle ngl

gentle star
#

I

#

love

#

you

#

😄

pearl pond
#

thanks for the help ❤️

#

i'll ask something if i'm stuck on something

gentle star
pearl pond
#

Conclure, right now I'm struggling with using the modules on the main project.

gentle star
#

Oo what’s the struggle?

pearl pond
#

do i need to do something with the modules on the gradle tasks?

#

like it's only compiles the main project without all of the modules

gentle star
#

Oh

#

In your main module

#

Add to the dependencies block

#

implementation(project(':whatevernamesameasinsettingsgradle'))

#

@pearl pond

pearl pond
#

ooh, like shading it into the main project

gentle star
#

Yeah

pearl pond
#

still it doesn't work, idk why

#
rootProject.name = 'BackpackCosmetics'
include 'v1_16_R3'
include 'v1_17_R1'
include 'PurpurHook'
gentle star
#

Is this on the?

pearl pond
#
dependencies {
    implementation 'me.aglerr.lazylibs.LazyLibs:LazyLibs:1.0'
    implementation(project(':PurpurHook'))
    implementation(project(':v1_16_R3'))
    implementation(project(':v1_17_R1'))
    compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
}
gentle star
#

Gh**

#

Oh yeah

#

Push to gh, and add me

#

I’ll take a look

pearl pond
#

kk one sec

gentle star
#

Ofc no need to add if it’s public

pearl pond
#

i trust you to not leak it xd

gentle star
#

Yeah won’t

pearl pond
#

wait, the build.gradle etc won't get committed

#

the file's name is red colored

gentle star
#

You need to add it to git

#

Right click it and add to git I believe

pearl pond
#

oh, on the unversioned files, i see

gentle star
#

Yeah yeah

pearl pond
#

i've invited you

gentle star
#

Dm the project link

pearl pond
#

What should I do with the java version?

#

The plugin will support 1.16 and 1.17

gentle star
#

Build against Java 8 maybe

#

Most stuff will still work

#

Also check DMs

#

I wrote some stuff there hehe

pearl pond
#

oh

#

i already do the interface thingy

#

On the main project there is interface class named NMSCosmetic and I implement that class on the modules.

gentle star
#

That’s the issue

#

Main has an interface that nms modules depend on,
So nms modules must depend on main

#

But main is also the final module thus must depend on the nms modules

#

Cycling dependencies

pearl pond
#

alright

#

i removed the compileOnly parent

gentle star
#

Move the interfaces to a new module called abstraction or something

#

Then let main depend on abstraction and any nms module

pearl pond
#

alright

#

and the modules will depend on the new module?

gentle star
#

abstraction -> purpur, nms

#

abstraction -> main

#

purpur, nms -> main

pearl pond
#

purpur and nms depend on the abstraction?

gentle star
#

Yes

#

That’s what I meant with the arrow

#

When working like this you’ll realize how often you might need an interface to segregate but that’s normal

pearl pond
#

wait, i got confused a little bit xd

#

so implement the abstraction on nms and purpur

#

and the main will implement the abstraction?

gentle star
#

No

#

First statement is correct

#

Main will not implement abstraction, but just depend on it

#

Cuz in main you’ll have to check what nms version then load the corresponding implementation

#

And for that you still need the abstraction interfaces on your classpath

pearl pond
#

how can i access everything inside the abstraction on the main?

gentle star
#

Wym

#

Let me see if I have an example

pearl pond
#

after i implement abstraction to nms and purpur, what should i do?

#

i've moved the interface there too

gentle star
#

@pearl pond

#

What’s ur gh name

#

aglerr?

pearl pond
#

aglerr

gentle star
#

Not finished lol but it shows what has to be done

pearl pond
#

so your lychee-implementation implement nms

#

and your main implement the lychee-implementation

gentle star
#

hmm yeah one way to put it

#

But don’t say implement

#

Say, depend

pearl pond
#

okay

#

still confused smh

gentle star
#

There’s a difference between implement and depend we first need to discuss

#

In java the notion of implement means mostly implementing an interface creating a concrete implementation

#

depend simply means that we are in need of a class/component to make our system work

pearl pond
#

I think I get that part, it's just because the thing called implementation on the build.gradle

#

even tho it's under dependencies but idk why i said implement

gentle star
#

Yeah the name is somewhat ambiguous

#

implementation is like compile scoped maven dependency

pearl pond
#

yup

#

and compileOnly is like provided right

gentle star
#

Yes

#

Tho maven is actually hiding the actual concepts of how dependencies work

#

Of course gradle does also but it makes it some what more conspicuous

#

We have two types of dependencies

#

Runtime and compile time dependencies

#

I can explain that later if you’re interested

#

Let’s get back in topic now

pearl pond
#

alright

gentle star
#

Let’s simplify it actually

pearl pond
#

so right now i have a abstraction module with a interface class in it

gentle star
#

so we have the module abstract

#

it has the interface TitleSender

#

.

#

Then we have one of the nms modules called v1-8-r3

#

It implements the interface TitleSender so:
TitleSender1_8_R3 implements TitleSender

#

but in order for v1-8-r3 to implement TitleSender it needs to depend on the module abstract

#

You understand so far?

pearl pond
#

yes, i understand it clearly

gentle star
#

Okay then we have another module called main not to be confused with the rootproject/parent module

#

in main we decide what implementation of the interface TitleSender we want to use

#

But to be able to use TitleSender in main, we also need to add the module abstract as a dependency to the module main right?

pearl pond
#

uh huh

gentle star
#

You cannot have a variable
Bukkit bukkit = new Bukkit(); if we don’t have Bukkit as a dependency right?

#

The class will be unrecognized

pearl pond
#

yes

gentle star
#

The same story for the module main

#

In order to be able to use the interface TitleSender from abstract we need to have the module abstract declared as a dependency in the module main

pearl pond
#

okay i understand

#

basically you need to depend on the module abstract in order to use the interface TitleSender

gentle star
#

Yes

pearl pond
#

so all of modules and main should depend on the module abstract

gentle star
#

Since the interface TitleSender is contained inside the module abstract

#

In this very case yes

#

——
So now we have this module tree:
abstract -> main
abstract -> v1-8-r3

right?

pearl pond
#

yes

#

both main and v1-8-r3 depend on abstract

gentle star
#

Now comes the tricky part

pearl pond
#

do you need like a module to handle all of the modules?

#

and on the main you will depend on that module (the one who handle all of the modules)

gentle star
#

yes

#

The main module needs to depend on the abstract module and the nms modules such that it can choose which nms module to use

pearl pond
#

I added API module which is the abstraction modules, and NMSWrapper module which is the "main" module maybe.

#

so on the NMSWrapper, I depend the API and NMS modules, and on the main I depend the NMSWrapper module, but I still can't access what's inside the NMSWrapper.

gentle star
#

Let me see

pearl pond
#

I've tried to depend on different modules (on the main build.gradle) but all of the classes from that modules still unrecognized.

gentle star
#

Hmm

#

I’ll help you more once I get home

pearl pond
#

kk

pearl pond
#

i'm heading off, gonna check it tmr

gentle star
#

AlrYeah

#

Just ping