How to create Intellij Idea project from existing sources with meaningful module names? - maven

When I create a new project from existing sources in Idea, it just creates multiple modules with names like main1, main2 etc and splits main and test folders in maven-like project structure.
Could I still create an Idea project with nice module names and structure?

Yes, you can rearrange classes by dragging and dropping, or just changing the package statements.
Having a maven like project structure is advised as this convention is relied on by many frameworks i.e Junit.

Related

building a jar library from a war project using maven?

We have a EAR project which has a WAR project. Maven is used, so pom.xml. As typical of any project, this project also contains a big feature (say Job Scheduling "JBS") among many other features. As it is planned to retire this whole project in the near future, it is discouraged heavily to spend much on working on this project (whether bugs or enhancements).
Therefore, for the sake of running the (JBS) feature as a separate application, the whole EAR project was duplicated (also to save time/cost). As a result, all the Java packages and classes (necessary for JBS project) were duplicated. In this situation, if we update one or more classes in the main project, this (JBS) feature project/application gets outdated (and needs update).
The fact is that this JBS feature project ONLY requires many packages of Java classes (from the main EAR-WAR project), and do not require 99% of the web modules and others. I am removing all the unnecessary things from JBS project. Then I would like to create a JAR library with all the java classes, so JBS project can have a dependency on this JAR.
I do not know if it is a good idea to separate these classes out of the main project (to create another Java project). I would like to continue to have these classes as part of the main project. Then, it will be good, as and when one or more of these classes are changed, a new version of the JAR will be generated (right away). And the JBS project would then make use of this updated JAR.
How can we accomplish this? I understand, through maven, we can do a build/package jar/war/ear on a project of that nature. I am not an expert with maven (and did not learn it systematically).
But, is there a way to create one or more JARs additionally from inside WAR pom.xml? In other words: I mean pom.xml of WAR will create a WAR. In addition to creating a WAR, can maven help create additional JAR? Or can maven create two packages out of one pom.xml?
Or should I create a separate module in the main project with all these packages/classes, and have its own pom.xml to generate the necessary JAR? For this, most probably I need to modify the structure of the main project. I would like to avoid this unless there is no way out.
Can you advice?
It seems like the best thing for you would be to create a multi-module project that both contains the JAR and the other project. This way, you can easily change/build them together, but you create separate artifacts.

How can I depend on a sub-project of the buildSrc project in Gradle?

I have a multi-module project inside buildSrc/.
I would like to use one of these sub-projects as a dependency of a "normal" (not build-related) project.
To make things clearer, the project layout is more or less like this:
buildSrc/
p1/
p2/
main/
main1/
main2/
build.gradle
Now, what I want is to make :main:main1, for example, depend on buildSrc/p1.
I have been able to achieve this by including buildSrc/p1 in both /settings.gradle and in buildSrc/settings.gradle, but that's not very good (it's basically duplicating the project in 2 separate project trees) and causes IntelliJ, for example, to fail to import the project properly (which is my main issue, actually).
Is there a good way to solve this problem without moving buildSrc/p1 to a separate Gradle project or repository (it's important that we keep being able to evolve the code in both projects together with minimal friction)?

How to make IntelliJ reference a local project for a dependency?

Working in a multi-module Maven project, call it "app." I need to work on the source of one of the dependencies, call it "lib", and be able to easily test/debug "app" against my changes in "lib."
In Eclipse this is an option for its Maven and Gradle plug-ins, and is obvious since Eclipse doesn't bind the concepts of "workspace" and "project" as tightly as IntelliJ does. When I cloned the repo for "lib", IntelliJ offered to create a new project for it, but how do I force "app" to use the local working copy of "lib" for compilation and runtime?
To put it another way, can IntelliJ basically encapsulate doing build install on "lib" behind the scenes so that "app" uses the updated (snapshot) of it?
The obvious, cleanest choice would be to combine the two projects into a common Maven multi-pom project. If that is something you can't do (perhaps the projects belong to different teams etc.), then I could imagine you could fake it by using symlinks.
Create a wrapper project with just a pom file and two modules. Instead of folders for the modules, use symbolic links to the actual file locations. Obviously the reactor root pom would not be the parent pom.
Now open the wrapper pom as IntelliJ project.
I don't know if this works, but it's worth a try.

How do I create a project based on multiple poms and allow refactoring between them?

Let's say I have several poms with dependencies on each other. There's a class in one project that is used in several others. I want to perform a refactoring (like rename on that class) that updates all the projects.
I tried to accomplish this by adding the maven projects via the Maven Projects pane. This lets me see all the code and compile, but when I try to refactor, I get an error message saying "Cannot perform refactoring. Selected field is not located inside project." How can I make all these maven projects behave like a single project?
edit Pebkac strikes again. I had problems with my poms. I fixed those, and now everything works as expected.
You want a multi-module maven project, with the modules defined in a parent pom. You then tell idea to create or open a project from the parent pom. All modules then form part of the project, and your refactorings should work.

Create a maven project to be used as a jar library in another project

I want that a maven project can be used as a black box jar. This is needed because second project was born its way, and I don't want to integrate its code by hand. So the best way is that this project is going to save it's data on db, but it should use a service offered by the "wrapper" project to save them.
The idea is simple, the secondary project can expose just a method to which I will pass the service that offers the save method as a parameter.
The secondary project should not have configuration files, but should rely on the father application's properties.
Any idea to do this fast and almsot good? Thanks for any suggestion.
EDIT 2013/03/07: The idea behind this is that the second project should generate a classic jar library that looks a properties file into the classpath of the host project. Something like Quartz/Spring/... you import jar and you provide the properties file.
I just defined some classes to load properties from the classpath, and some interfaces to make the two projects interact.
In pom.xml of the parent project I imported the child project excluding it's dependencies to avoid conflicts.
It was a pretty easy task at the end.

Resources