intellij - keymap / hotkey / shortcut per module / project - intellij-idea

I have many projects
I use a hotkey to deploy files built externally to my deploy folder, as intellij is not doing that or is doing that very very unreliably and slowly.
so say in project A I have a shortcut CTRL+SHIFT+Z to deploy all files I need to the deploy folder with a shell script. In Project B I have a different shell script (obviously) to deploy all I need. But I dont want to create a new shortcut, I want to reuse CTRL+SHIFT+Z but that doesn't seem to work
Is there a way to define a shortcut / hotkey on module basis? or a different solution?

It is not possible at the moment, you can set several different keyboard layouts and switch them manually. Also there is a feature request to provide project level keymap: https://youtrack.jetbrains.com/issue/IDEA-127090

I just use always the similar ant build file in all projects doing a simple copy, and assign the shortcut to that ant build file:
so in each project I have a build.xml in the root with this content
I guess it works because the "target name" is always the same in each build.xml
<project name="joomlaPHC" default="copy-css" basedir=".">
<target name="copy-css"
description="copies css files" >
<copydir src="/home/myuser/IdeaProjects/MYPROJECT/src/public" dest="/var/www/html/MYPROJECT.local/public"/>
</target>
</project>
the shortcut seems to work
don't forget to assign the jdk
hope it helps

Related

Executing post-build step Intellij IDEA CE 2020.3?

I am using IntelliJ IDEA CE 2020.3 to build a simple JAR file. After the build, I'd like to copy the created JAR to a library directory.
I am using the Ant plugin that comes bundled with the IDE. I can't seem to find the underlying Ant build/control files that make the whole thing work. I assume Ant uses the .XML files that are part of the IDE's project settings, but this is unclear.
In any case, is there a way to add the "copy" step that I mention above?
Do I have to either use the built-in Ant or take it over completely myself?
Can I edit the default that ships with the IDE?
All,
So after some experimenting, I found that if I manually create the build.xml file, I can execute post-build steps. For my example here, I created the following, simple build.xml and added it to the top-level IntelliJ project directory (where the .iml file lives):
build.xml (manually created)
<project name="mylib" default="copy-file">
<target name="copy-file">
<copy file="out/artifacts/mylib_JAR/mylib.jar" tofile = "./mylib.jar" />
</target>
</project>
Note that the directories are relative to the project directory.
IntelliJ IDEA enabled me to add the copy-file task to augment the default, built-in build. To configure your tasks via the IDE, open the Ant tool window via the View/Tool Windows/Ant main menu item.
I hope this helps someone out there!

Command line generation of IntelliJ IDEA project files?

I prefer having one IDEA project per task I'm working on. If it's a Gradle project, I can run gradlew idea to generate the project files then rename them to be indicative of the task I'm working on (so that when re-opening from IDEA a project, it's obvious what the task is and IDEA is able to list several tasks for the same Gradle project). This works well enough if it's a Gradle project, but if it's not, I'm left with using the IDEA GUI to open the project by pointing to the working directory. Is there a command-line way to generate the IDEA project files so I can rename them prior to using the GUI? Being able to do this would also obviate the need for using gradlew idea for this purpose.
Using the GUI, create the project by pointing it to the build.gradle file or project root directory. Once the project is created:
click the File menu
click the Project Structure menu item
change the Project name text value

In IntelliJ IDEA, how to copy non-source assets to output folder during build?

I have a project in IntelliJ IDEA, inside that a couple of modules and one of my modules has two build configurations. One of them needs to copy a <projectroot>/tools folder to its out/production/<BuildConfigurationName> folder. Can IDEA somehow automate this?
The accepted answer above is incorrect. IDEA can do this (without ant/gradle) via the artifacts system (accessed via Build menu or project settings). Any one artifact job copies multiple files/folders/build outputs to a chosen location (optionally jarred) and can be set to automatically run on make.
Artifacts can even be chained, i.e. output from one as input to another.
Can IDEA somehow automate this?
Not directly, no. Ultimately IDEA is an IDE and not a build tool. While it can do a lot during a build, it does not have the ability to copy non-source files to an alternate directory, let alone a dynamically named directory.
If you marked the tools directory as a source directory (and none of its contained file types were set in the "Ignore files and folder" setting at the bottom of the "File Types" settings dialog), IDEA would then copy the tools directory to the out directory. But renaming requires a more sophisticated build tool.
Ultimately, the "ideal" or "best practices" solution would be to build your project using a build tool like Maven, Gradle or Ant for which this type of thing would be a snap.
If that is not an option, or for some reason you really want IDEA to do the build, the best thing you could do is to write a simple Ant script to the copy for you. (Or possibly Gradle, I do not have much experience with Gradle yet. Maven could do it, but it'd be a bit cumbersome compared to Ant.) In any Run/Debug configurations, you can define the ant script target to run before or after the IDEA "make" in the Before Launch section. (You can set that as a default for any newly created configurations by configuring it in Defaults on the left). If you run your build manually, you can assign a shortcut to the ant build and then run it and the make in sequence. Alternatively, you could record a Macro (Edit > Macros) to run both in sequence and then (optionally) assign the macro a keyboard shortcut.

What is the command line option to pass into the activator framework to generate an intellij project?

I'd like to generate the intellij project files from a typesafe activator project via a script - is there a command line interface or command i can use for this purpose?
(i wasn't able to find directions for one online, or in the usual help locations)
Please note that since IntelliJ IDEA version 13 it is no longer necessary to generate files for IntelliJ IDEA. sbt support is now build in, you can open/import the project by opening your build.sbt with IntelliJ IDEA: http://blog.jetbrains.com/scala/2013/11/18/built-in-sbt-support-in-intellij-idea-13/
Remember that Activator is just an sbt wrapper with optional UI mode. So what you want is sbt-idea:
https://github.com/mpeltonen/sbt-idea
The Activator UI will auto-add this plugin and then (on the Code tab) it has an "open in" menu item to generate the intellij project.
If you want to script it, there are two steps:
add the plugin (either drop an idea.sbt in project/ directory or put it globally in ~/.sbt/0.13/plugins)
run activator gen-idea

logback.xml and running application from JetBrains IDEA IDE

When I develop application in IDEA, where should I place logback.xml for it to have an effect on the application?
It seems when you run/debug IDEA doesn't make any jars and doesn't invoke Maven to build something. Does it execute main() directly from compiled *.class file? If so, where can I put logback.xml so that it would have effect?
logback.xml should be available in the root directory of your CLASSPATH. When you run your application, the full CLASSPATH is printed at the very beginning. When I put logback.xml in /src/main/resources (Maven project) it works without any problem. Also putting it in /src/test/resources with logback-test.xml name has presence.
Simply run:
getClass().getClassLoader().getResource("/logback.xml");
And see whether it returns something or null.
If you are not working with Maven project, open Project structure (Ctrl + Alt + Shift + S) and add in Modules section select folder containing logback.xml and mark it as Sources (blue icon).
For me: I simply needed to re-build the project (not just re-run or re-compile the project). Changing the src\main\resources\logback.xml did not affect logback because the class loader is picking up the logback.xml that is in the target/ folder, not the /src folder. This makes sense since target is the run environment. Therefore, a build is required to transfer the new xml file over to target.