How to import gradle ear artifact to Intellij - java

I have the following situation:
I am trying to write a little project in Java which should produce a single EAR file which contains a single WAR. There might be some JARs in the future, but it is not important now.
I need to use gradle for build automation and Intellij for developing. I have some problems with synchronization between those tools.
I have prepared a gradle project ‘ear-app’ with the ‘ear’ plugin applied. It depends on a second project ‘web’ which is war. It works well with gradle wrapper. ‘build’ task builds ‘ear’ file.
Unfortunately Intellij has not recognized the
‘ear’ artifact. In “Project Structure”, there is only web application artifact which comes from ‘web’ project.
Is it possible to make Intellij be able to recreate ‘ear’ artifact?
I do not keep intellij files in my repo, so I need a solution which bases on gradle configuration.

Seems like this was asked over here in the meantime, and got this response from ɐuıɥɔɐɯ:
Seems automatic artifact configuration is not implemented yet in IDEA

Related

Steps to change IntelliJ GitHub project to download and build source code for dependencies

Using IntelliJ IDEA, it is often a straight-forward task to check out a project from GitHub and get it to build locally.
Once the base project is imported from GitHub, the IDE will download artifacts which will allow the main project to run. The dependencies can be examined by using File > Project Structure... > Libraries.
So the IDE downloads dependencies to allow running, but not to build from source. The IDE is able to decompile classes, but the IDE will not automatically download the source code for those dependency libraries so that the programmer can alter the code.
This question is about the steps required in the IDE and project configuration such that a selected dependency will be built locally, and thus allow the programmer to alter the code.
What I tried was to import the project on which the main project was dependent, as a separate project, then configure the main project to utilize the local project instead of the downloaded artifact. The first step, downloading the sub-project and getting it to compile, was completed successfully.
So I ended-up with two projects, the main one, and the one on which the main project depended. The task at hand, if this was the appropriate way to get this done, would be to open the main project and take some action to convince the main project to use the local build, rather than the downloaded runtime "jar".
First, I edited the POM.xml to comment out the dependency for the sub project. Checking File > Project Structure... > Libraries, I could see that it was gone, and the build now failed (as expected).
I went to File > Project Structure... > Libraries > + (plus sign) and poked around with New Module, and Import Module, but I was not able to convince the original project to use the locally available sub project. The result from various attempts was that code in the base project was not able to import from the sub project (unable to compile).
What are the specific steps to take in the IDE to get what was a runtime dependency "jar file" to instead to build locally, and use that instead?
Use a SNAPSHOT version for the dependency (you'll need to change this in both your project's pom.xml and the dependency's pom.xml, so if the current version is 2.0.0 change it to 2.0.0-SNAPSHOT)
Then you can edit the dependency's code and run mvn install in the dependency to provide the new version of the dependency to your project.
TLDR: there is no simple and straight-forward way of downloading a project's code and the code of its dependencies to rebuild it in one go as a complete chain.
Your project depends on several other artifacts. From the screenshot, we may assume that this is a maven project, at least we can be sure that there artifacts with compiled classes available for download, because this happends during build. You can view the compiled classes of your dependencies, because Intelli has the capability of decompressing jars and decompiling code, obviously, but the contents you are viewing is read-only.
Sidenote: Maven convention is to create 3 separate jars for each project. One with compiled classes, one with source files only and one with generated documentation. By default intellij may not download these, but you can force it (right-click on pom.xml -> maven -> Download sources and documentation). This will attach the actual source code instead of decompiled classes to your IDE, so it's much easier to understand the code - but still, there is no option to modify it - it's still read-only extract from some jar.
So what if you want to actually edit the source? You have 3 options, all with its own set of problems that need human intelligence to solve:
You extract the decompiled source from classes jar
You extract the attached source from sources jar
You check out git repository of the dependency
Now, beware of the downsides of each approach:
You can be sure that the decompiled source matches your project dependency 1:1. But decompiled code is not easy to read, missing comments, etc. Also, some projects may not ship their build scripts with the classes jar. Anything more complex than mvn clean install may turn out to be a blocker.
You can be reasonably sure the code matches your project dependency, but this actually is not a given. There is a chance of human error, causing the sources to actually not match the compiled classes (build from different revision or whatnot). Much depends on the quality of the project, the discipline put into the build process and care to avoid environment specific configuration that is not part of the source. The larger and older is the project, the less chances are you are able to recompile it successfully using only src jar.
A sane man's approach. You should have your build scripts, readmes, tutorials, etc. Except, of course, if we are talking some obscure company internal project with zero effort put in its maintenance. Surely, there are the same issues as before: not all projects are rebuilt easily on any environment. There may be steps upon steps required for your workstation to be configured as expected. Hopefully, self-respecting open-source java projects are easy to build, but again - not a given - not all project are open-source, not all are self-respecting.
Important note: When checking out the git repo of your dependency - you must also make sure that you are using correct revision. If the project is maintained with respect for git tags/branches naming convention - you are in luck. Not a given by any means.
All the above is enough to discourage any attempts to automatically decompose dependencies to compilable units by your IDE, and all the burden is put into you. So let's assume the best - our dependency is a simple, self-contained java application that is easily built using simple mvn clean install. You have it checked out in a separate project in your IDE. You identified correct git revision that matches version your project depends on.
Now let's apply your little change and test it. First thing you want to do is change pom.xml of your project to use a made up version of your dependency. It should be a -SNAPSHOT version for clarity and tidiness. You may of course build your modified dependency with real release version - but please be wary of how maven manages dependencies. If you install version 1.0 yourself - it stays in your local repo forever. You will forget about it, and will be using your fake 1.0 version when building all other dependent projects unless you manually locate and remove it from repo. So stick to 1.1-SNAPSHOT.
Now every time you need to apply a small fix to your dependency, execute mvn clean install in its repo, then make sure your actual project depends on the correct new SNAPSHOT version, execute your maven clean install and that's it.
Note that all this has very little to do with Intellij. You are not expected to modify any library paths, advanced project settings, or links to jars. Stick to modifying pom.xml and you are set.

How to add Spring jars to Java Project mirroring folder in git repo

Long title, but pretty much explains it. I've pulled a git repo (spring rest tutorial http://spring.io/guides/tutorials/rest/) which contains multiple standalone java projects each in separate folders. Each of these projects contains gradle build files as well as gradle itself (no need to install gradle), AND the necessary Spring jars (likely in the gradle-wrapper jar). I've created a java project in eclipse that mirrors one of the folders and the changes in eclipse are picked up no problem and it builds fine.
The problem I have is that the Spring dependencies aren't on the Eclipse build path, so I can't use all of the nice Eclipse features (function completion, auto imports, etc.). There's only one jar in each separate folder from the git repo and it's called gradle-wrapper.jar. My guess is that this contains all the Spring dependencies, as the project builds fine, assuming I've typed everything correctly and manually added correct import statements.
Is there a way to set this up so that I'm not getting all these ugly errors in the java project? I attempted to add the gradle jar to the java project build path, but this had no effect. I suppose one option would be to add the spring dependencies separately, but then the Spring on the build path wouldn't necessarily match the Spring dependencies used by gradle for the actual build.
Gradle projects don't package all the dependencies in the repository; one of the primary reasons to use Gradle or Maven is that they'll handle dependencies for you. You need the Gradle Eclipse plugin and to Import->Existing Gradle projects.

Eclipse makes wrong choice of JAR as project dependency when class presents in more than one library

I work on a big Java application and I'm having problem compiling it under Eclipse Kepler:
the application is based on Maven 3.1.0 and successfully compiles there
I generate Eclipse configuration (project files) using mvn eclipse:eclipse
The problem is that certain classes present in more than one JAR (e.g. imagine a class Http and two versions of this class where newer has more methods) and Eclipse makes a wrong choice of the depending class (older one) for particular project which makes it not compilable.
I tried to move Jars up/down in the project dependencies and it helps in certain situations, however, it means that I'm changing configuration changed by Maven.
Is it possible to configure Eclipse so that is "smarter"? Is it caused by Maven (POM files, a bug in Maven's eclipse plugin, ...) although maven compiles the project without any problems? Any other suggestion?
You should not use mvn eclipse:eclipse. The official way today is to use the m2e plugin (which is much smarter) with File->Import->Existing Maven projects.
When you open a pom.xml file you can see the dependency hierarchy and why a given jar was chosen.
(Note that most but not all standard distributions of the latest Eclipse contains m2e. If your do not you can download it from the marketplace, but it may be easier to download a distribution that has it).

IntelliJ Idea and Java EE Development / Deployment

I'm switching from Eclipse to IntelliJ Idea and had some, homemade i guess, problems while deploying.
In Eclipse usually my (main-) project contains 4 subprojects:
EAR
EJB
Shared (with JPA Entities, JPA Facet and so on...)
WEB (JSF, REST)
I know that JetBrains way of organizing is another. So i create a new Project and check all desired technologies i need (EJB, Web, CDI for example). When i try to deploy the project there is as cdi ambigious error, because the class is in the EJB artifact and also in the Web artifact. So my stupid way of thinking was, to delete the compile output from the web artifact, but now the files are not accessible in the Web-Project anymore (CNFE while calling).
So please, what is the correct doing if i'm trying to develop a project with EJBs, JPA, Web (JSF, REST). That could not be so hard and i'm going insane ;). Thank you!
Guten Abend,
I think you should allow to build your project from the command line. I use IntelliJ for large projects and I always make sure that I can build the thing from the commandline with a mvn clean install since it is sometimes needed and good not to depend on an IDE. I recommend that you divide your projects into the subprojects that you mention and make a pom.xml for each project and put the source into source control e.g. subversion. Then you will be able to checkout the project from subversion and it will load up neatly in IntelliJ iff you got it all configured right.
So if you haven't already, consider using Maven and Subversion (or some other VCS) for your projects and it will simplify your work.
If you provide more details about specific files and specific error messages we can help you more to move forward, and these were my general recommendations.
My setup in IntelliJ that builds a large project from several subprojects looks like the following.
When done this way, I can rebuild individual subproject without being forced to rebuild the entire thing just because of one small change. And I also can build everything from the commandline using the maven command mvn clean install

Build play! project with maven

I am using play 1.2.4 to create a web app. It works together with some other applications which are maven projects: they are compiled and resolved (dependencies) with maven.
Now I need to modify my play app so it can also be compiled and started with maven.
Therefore I download maven (3.0.4), installed the maven modul and did everything according to https://github.com/wangyizhuo/play-maven and http://www.playframework.org/modules/maven-head/home
I manage to automatically create a pom file in my project. The problem is that the jars from the play framework are not copied into the lib-folder and when I try to execute mvn package they are missing.
Is there a way to get the maven module to work properly? If not, is there another possibility to compile and start the project from maven (i.e. intermediate ant-file that can be executed by maven?)
Many thanks in advance!
This explains it pretty well. I havnt looked at the module you are refering too, but this shows you how you can create tasks and inculde directories in your build.
Do you need to use maven to build/run it? If not it looks like there is a community contributed extension that allows you to use maven from within play.

Categories