Copy IntelliJ Module - intellij-idea

How can I copy IntelliJ Module into new Project?
Currently when I add Module to Project Module is just referenced instead of making new Copy that I can change without impacting original Module.

Related

How do I rename my entire project in IntelliJ without having so many manual steps?

I have IntelliJ 2019.2
I occassionally mis-name my project during creation.
I have to quit IntelliJ, renaming the folder, opening project again and renaming package and project module manually as well.
Any way to improve this?
Please follow the discussion on the issue: Renaming a project in IntelliJ IDEA
There are project, module name, name in file system etc that can all be different and can be renamed. Rename of folder can be done in file system, project, module rename in the Project Structure settings.

How to add a jar to the external library for a project w/o disappearing after sync and with imports working?

Presently having an annoying time getting a jar added to the external library for the project, then in turn not disappear when syncing and the imports working. Adding I figured out and answered in another question. The issue is to keep persistent and accessible to a jar I create within the project for import.
I am not sure if I am missing a step or forgot to set something. I am using a modified gradle (forgegradle) to create the project. Have not found a solution with the documentation, or any for IntelliJ yet. I am generally new with IntelliJ, choosing to use it instead eclipse which I have previously used.
The goal is a to create an add-on for a mod to another jar. The main jar already in the external library from the start, now attempting to add the mod to it. I could modify the mod, but it is not my code, so rather not simply modify it directly and repackage it.
a jar added to the external library for the project, then in turn not disappear when syncing and the imports working
If you are using an external build tool / system that syncs with IntelliJ it is recommended to use that build tool / system to add dependencies.
IntelliJ will always take a backseat, and treat the build tooling / system as the source of truth for the project model as best it can.
You mention you are using gradle, I would recommend adding the dependency as a managed dependency that is, let gradle download it from a repository, and resolve the dependency/library itself.
If you can not do this, and you can't host a repository yourself, The next best recommendation I have, is creating a 'libs' folder inside the project, that contains jars that can't be found in repositories (They may be mods or plugins that were never published)
You can read up on how to add a library folder to gradle here: How to add local .jar file dependency to build.gradle file?

How to make IntelliJ reference source code in another module?

I have a typical project structure:
- root-dir (not a project)
\- core-module (a gradle project)
\- application (a gradle project)
Both core-module and application are imported into IntelliJ and kept on Auto Import. In application's build.gradle, core-module is referenced as:
compile('my-group-id:core-module:0.2.0-SNAPSHOT')
where 0.2.0-SNAPSHOT is the current version as declared in core-module's gradle.properties.
In application, when I try to view a class from core-module, I'm brought to the source code in core-module-0.2.0-SNAPSHOT-sources.jar, instead of the corresponding source code in the core-module module.
I know I can manually add core-module as a module dependency in application, but next time anything in application's build.gradle changes, auto import will overwrite that dependency.
Is there any way to make IntelliJ recognize automatically that I'm trying to view a class from another module and go there instead of the downloaded sources jar?
Furthermore, is there any way to make IntelliJ always prefer the core-module module over the dependency jar, not only for code viewing, but for building/running/debugging/etc.?
All the source files are in Kotlin, FWIW.
Use Gradle's composite build. Gradle has composite builds https://docs.gradle.org/4.4/userguide/composite_builds.html that allow one to 'include' a build directly, rather than from a repository.
IntelliJ also supports this functionality. This was added in 2016.3.
Here's a webcast:https://blog.jetbrains.com/idea/2017/03/webinar-recording-composite-builds-with-gradle/
In the Gradle tab, right-click on your application module. The menu will have a 'composite builds' option. On the dialog that appears, check the 'core-module' module and close.
Now, right-click on application module and do a 'refresh Gradle project'. I've found if I don't do this, the dependency doesn't get updated correctly.
To verify, look at the dependencies under the sourceSets. Instead of a version #, it will now look like a module dependency.
This provides many benefits. One is the navigation you were looking for. In addition, any changes made in core-module are immediately available, and used for the application.
Refactor a method in core-module that is used by application, and IntelliJ will refactor all usages.
Enjoy!

Why is my library not being recognized after importing my project?

I'm using the JDBC library in my IntelliJ project (mysql-connector-java-5.1.40-bin.jar)
I put it into a folder named lib and used right click > Add as Library to add it as a library. It worked fine.
Later, I zipped the project and moved it to another computer. After unzipping it and importing it in IntelliJ, it gave me the error SQLException: No suitable driver found for jdbc:mysql, which means that it couldn't find the library.
I looked through the file explorer in IntelliJ and it showed both the jar and XML file, and the XML file was pointing to the right location (jar://$PROJECT_DIR$/lib/mysql-connector-java-5.1.40-bin.jar).
I added the jar file as a library again and now it works. But how can I make it work without having to readd it each time?
Use Gradle (or Maven) for building and dependency management. IDEA should import a Gradle (or Maven) project just fine.
The problem was that I was overwriting the IntelliJ Module Library (.iml) file.
When you import a project to the same folder, IntelliJ asks you whether you want to overwrite or reuse the IML file. Since Overwrite was the default option, I selected it, but that caused it to forget what libraries it was using.
By choosing Reuse instead, it works perfectly.

Is it possible to create an IntelliJ plugin to create a new "Module Type"

Is it possible to create an IntelliJ plugin to create a new "Module Type"?
I want to create a new module type in a project that can be dependent on other modules of any type in the project, and be a dependency for any other modules in the project, and when building the new custom module type execute code specific to the new type of module (i.e.: its custom compiler or other external command or process).
Check IntelliJ IDEA Community Source code, for example Android plug-in adds a new module type.
Right now there is a major API redesign in progress for IDEA 12 in order to provide templates for modules and projects. See this directory for Android templates.