Please follow these steps to setup your development environment using IntelliJ IDEA and Docker.
Let us know in case you need additional help.
This guide uses Intellij IDEA 2020.3. Always use the latest Idea version available. There may be slight configuration differences between idea versions, but we believe you can figure things out .
This guide is intended for Windows developers and uses powershell and not cmd for any CLI examples.
My windows account username is crist
so whenever you see that, please replace it with yours.
Install git
Download and install git from https://git-scm.com/downloads, then make sure it is added to your PATH.
To check if itās added to PATH open powershell and run:
git --version
You should get an output similar to this:
PS C:\Users\crist> git --version
git version 2.22.0.windows.1
Clone metasfresh project
All the metasfresh projects will be located in
C:/work-metas
this is the root folder of our project.
The following code will create work-metas
then clone all the metasfresh modules needed from github:
mkdir c:/work-metas
cd C:/work-metas
git clone https://github.com/metasfresh/metasfresh
Install OpenJDK Java 8
Download and install JDK 8 from AdoptOpenJDK, then set the JAVA_HOME
path variable.
To add the path variable using powershell with administrator rights, run:
setx JAVA_HOME 'C:\Program Files\Java\jdk1.8.0_212'
SUCCESS: Specified value was saved.
Install Node.js
Download and install the latest LTS version of Node.js. This is needed for the React metasfresh-webui-frontend
and for metasfresh-e2e
projects.
Install Postgres Command Line Tools
Thereās no need to install the full Postgres database. Metasfresh uses psql
for running the sql migrations, and it is found in the Command Line Tools.
Download the installer for postgresql version 10 (not a later version) from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads, and select Command Line Tools:
then add the bin
folder to Path with
$PATH = [Environment]::GetEnvironmentVariable("PATH", "User")
$pg_path = "C:\Program Files\PostgreSQL\10\bin"
[Environment]::SetEnvironmentVariable("PATH", "$PATH;$pg_path", "User")
but modify $pg_path
to the real directory on your system. Donāt forget to start powershell with Administrator rights.
Set up apache maven
Metasfresh uses maven and even though Intellij Idea has maven built-in, we have noticed that if something breaks in intellij (eg. intellij shows an error that some file has compilation errors even though logically everything should be in order), it is much easier (and less time consuming) to recompile the metasfresh project from CLI using maven.
Download maven zip archive from https://maven.apache.org/download.cgi
Maven has no installer and thereās no need to add maven to PATH, so extract the archive to C:/
then rename the folder to C:/mvn
from C:/apache-maven-3.6.3
(or whatever other version is currently available).
In the end you should end up with a folder structure on the disk such that mvn executable is found in C:\mvn\bin\mvn.cmd
. Please note that C:\mvn\apache-maven-3.6.3\bin\mvn.cmd
is the wrong path for this tutorial.
To test that maven is installed in the correct folder, run:
C:\mvn\bin\mvn.cmd --version
and you should get output similar to:
PS C:\Users\crist> C:\mvn\bin\mvn.cmd --version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T22:00:29+03:00)
Maven home: C:\mvn\bin\..
Java version: 1.8.0_212, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_212
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
PS C:\Users\crist>
Configure maven settings.xml
file
Copy settings.xml
from
C:\work-metas\metasfresh\misc\dev-support\maven\settings.xml
into
C:/Users/crist/.m2/settings.xml
file (create the .m2
folder if it doesnāt exist).
Compile the project using maven
This has to be done from the command line (powershell), because intellij ideaās Maven->Generate Sources and Update Folders for all Projects
option doesnāt work for metasfresh. Some of the generated sources for external .xsd
files are not created.
Here is the youtrack bug about this: https://youtrack.jetbrains.com/issue/IDEA-256661
This is a long-duration action, since weāre compiling the project and also downloading all the dependencies.
Run the following code in powershell (make sure to replace crist
with your username:
$start = Date
$env:JAVA_HOME = "C:\Program Files\Java\jdk1.8.0_212"
$mvnSettingsFile = "C:\Users\crist\.m2\settings.xml"
cd C:\work-metas\metasfresh\misc\parent-pom\
C:\mvn\bin\mvn.cmd -T 2C -DskipTests --settings $mvnSettingsFile clean install
cd C:\work-metas\metasfresh\misc\de-metas-common\
C:\mvn\bin\mvn.cmd -T 2C -DskipTests --settings $mvnSettingsFile clean install
cd C:\work-metas\metasfresh\backend\
C:\mvn\bin\mvn.cmd -T 2C -DskipTests --settings $mvnSettingsFile clean install
echo "Elapsed: "
(Date) - $start
When this step is finished, you will see the following:
Elapsed:
Days : 0
Hours : 0
Minutes : 0
Seconds : 7
Milliseconds : 671
Ticks : 76716038
TotalDays : 8.87917106481481E-05
TotalHours : 0.00213100105555556
TotalMinutes : 0.127860063333333
TotalSeconds : 7.6716038
TotalMilliseconds : 7671.6038
Install and set up docker
Installation
Follow the tutorial here to download and install docker: https://docs.docker.com/docker-for-windows/install/.
Note that you will have to restart your computer after the installation.
Install Jetbrains Toolbox and download Intellij Idea Ultimate
Download the installer from https://www.jetbrains.com/toolbox-app/.
We recommend using the Toolbox app as it helps tremendously with keeping intellij up to date, using different intellij idea versions for different projects and managing your projects.
Note: This guide is for Intellij IDEA Ultimate. Community edition might work.
We recommend the ultimate edition as it has additional features for web/spring applications.
E.g: autodetects spring and JEE applications and docker configurations, we have already setup data sources for various databases in metasfresh, and is also helpful for javascript development.
Configure maven in intellij
Start Intellij then go to Configure ā Settings
In Build, Execution, Deployment -> Build Tools -> Maven
make sure the path to the settings file is the one you downloaded previously.
In Build, Execution, Deployment -> Build Tools -> Maven -> Importing
make sure the items are checked/unchecked as below.
If possible, select the JDK used for importing as Java 8 and not the internal JRE 11. If that is not possible, it will be done later.
Import metasfresh in intellij idea
Copy the intellij
development settings
Copy the .idea
folder from
C:\work-metas\metasfresh\misc\dev-support\intellij-idea\
into
C:\work-metas\
.
In the end you should have a folder C:\work-metas\.idea
which contains runConfigurations
, codeStyles
and other folders.
Copy the metasfresh
development application.properties
Copy the metasfresh
folder from
C:\work-metas\metasfresh\misc\dev-support\application.properties
into
C:\work-metas\
Merge the folders and override any existing files if asked.
This copies all the settings needed to connect to the docker instances of postgres, rabbitmq, and sets the correct java application ports.
Choose Projects -> Open
Select folder C:\work-metas
Now the importing starts. Intellij will show you multiple notifications. You can enable some of them:
Always download pre-build shared indexes:
Show Spring Boot run configurations in Services tool window:
You will see this toolwindow:
Open Project Structure
via CtrlAltShiftS.
- Under
SDKs
, make sure your JDK 8 is visible in Intellij. If it is not in that list, press the+
button and add it.
- Under Project, make sure the
Project SDK
is yours
Press,Apply, OK
to submit.
Open Settings via CtrlAltS.
In Build, Execution, Deployment -> Build Tools -> Maven -> Importing
select he JDK for importer
: Project JDK
.
Add the pom files
In the Project
toolwindow right click metasfresh/backend/pom.xml
and choose Add as Maven Project
This step will possibly take a long time, as all the dependencies needed by metasfresh will be downloaded.
The import process will give an error, because we need to add more poms to intellij:
metasfresh/misc/parent-pom/pom.xml
metasfresh/misc/de-metas-common/pom.xml
At this point, all maven modules should be imported successfully.
If youāre asked to Download pre-built shared indexes
, choose Always download
Customize Intellij
Configure Services
toolwindow
Press ā4 squaresā and disable Configuration -> Type
Press āplusā and chose āRun configuration typeā and chose the following:
Docker
npm
Remote JVM Debug
In the end, you should see the following Run Configurations:
VCS on steroids
Press CtrlShiftA, type Registry
and select the entry Registry...
Scroll down until the option: vcs.commit.tool.window
appears and uncheck it!
Configure intellij to work with docker
Open Settings via CtrlAltS.
In Build, Execution, Deployment -> Docker
press +
and chose option Docker for Windows. You should see a
Connection successful` message.
Press Apply.
Configure intellij to work with node
Open Settings via CtrlAltS.
In Language & Frameworks -> Node.js and NPM
ensure that Node interpreter
and Package manager
are the ones you installed.
Press Apply Ok.
Run metasfresh from Intellij
Install infrastructure: postgres and rabbitMQ in docker
In Services
toolwindow, select infrastructure
and select Run
:
At the end you should see the message: Compose: infrastructure' has been deployed successfully.
Install dependencies for frontend
In Project
toolwindow, select the file metasfresh/frontend/package.json
, right click and run npm install
:
Copy the file
metasfresh\frontend\config.js.dist
into
metasfresh\frontend\config.js
without changing anything in it.
after_import.sql
Ask the metasfresh team for our after_import.sql secret sauce for developing on metasfresh and creating valid migration scripts. You need to run this mmigration script manually.
Run configuration Run SQL Migrations
This is needed after every git pull from master. It updates the local database with changes from your coleagues.
In Services
toolwindow, select folder all local
, right click and select Run
. The 2 java classes, along with the frontend should start.
Youāre finished!
We await your PRs. Good luck !
Optional (yet suggested) steps
Use Eclipser plugin
- There are some eclipse launcher files in the project. You could install eclipser plugin and
convert the files whenever you need them. Just right click on a ā.launchā file and youāll find theConvert with eclipser
option.
Eclipse and IntelliJ IDEA interop
Eclipse can only find // todo comment
s if todo is in caps rage. To do this you should go to Settings -> Editor -> Live Templates
and add a new template as follows:
Learn your tools
It pains me greatly when i see people using the mouse and searching through menus to accomplish some action. Most often than not your IDE has a keyboard shortcut for doing a particular task. USE. IT.
- Read all the
Tip of the Day
tips - Install the plugin
IDE Features Trainer
and do the tutorials there - use the shortcut Ctrl+Shift+A
- use the shortcut Shift+Shift
- let the IDE do refactorings for you, instead of editing everything manually