Monday, July 31, 2017

intellij: how to deploy to two folders?

Leave a Comment

The general question is: how to work with many different git repos at the same time in one intellij project. Where the git repos need to be inside the main application (that is one git repo too). I cannot use symlinks because I cannot commit those

I have 2 git repos

one is for the main app, the other one is for a library I am using in several projects.

Here is how it goes: I have the main app. Via composer I add my library / package to the application.

The problem:

folder structure:

to develop

IdeaProjects/myappA

note: there is are as well IdeaProjects myappB etc

IdeaProjects/mylib

in myappA there is

IdeaProjects/myappA/vendor/mylib

server deploy folder:

/var/www/www.myappA.com/

I do a lot of changes to the library, I have it open as another module when I work on myappA so I do code changes to mylib in that folder / module that actually contains the original source code of mylib. Now i don't want to composer install or update each time I do a tiny change. So what I do is I deploy via intellij the files from the library mylib each time on save directly into the composer install folder of my main application e.g. to IdeaProjects/myappA/vendor/mylib. Now the problem is, I need to deploy it as well to the server deployment folder. But there seems no way to deploy files to two folders out of the box with intellij.

What else can I do?

currently I manually use a short key to trigger an ant build that then copies the folder IdeaProjects/myappA/vendor/mylib to the server deployment directory.

2 Answers

Answers 1

There are multiple solutions depending on your setup:

solution inside intellij: just import mylib as a module inside your myapp project Go to File > Project Settings > Modules, click the + and choose import module import module

git native solution: Use submodules

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

Note that there are some quirks when working with submodules, especially the way to keep the referenced submodules up-to-date

For completeness: if you were using gradle or maven instead of ant, you could use their respective projects views and use the + to add multiple build.gradle or pom.xml files, which would automatically import those projects as modules into intellij.

Answers 2

I think the module approach does fit your case and yes you can have a different git repo per module. Right click on your project root new->module or file->new module from existing source

Intellij should also detect every git repository automatically in your project if you check Settings | Version Control you should see the list.

You can also speed up some operations such as git pull instead of having to pull from every repository (VCS -> Git -> Pull) you can do VCS -> Update Project or ctrl-t (cmd-t on mac)

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment