Make maven generate dependencies even with errors - java

This feels like a really stupid question but I haven't been able to find an answer.
I'm working on a maven project but I do most of my development in eclipse. Is there any way for me to force maven to generate all of my dependencies under target even if there are errors in the code? I set my eclipse project's build path to use the jars under target/dependencies/jars, but calling mvn clean kills them and if there are any errors in my code causing it to not compile mvn package won't create the dependencies but will instead just crash saying BUILD FAILURE. This makes the problem even worse since instead of seeing the actual errors my eclipse will just bombard me with errors everywhere since all of its dependencies just died.
Or maybe the way I'm working with it is just stupid and there's a better way.

Are you using the m2e plugins for Eclipse to process maven projects, or simply importing the projects as general ones?
If the latter, you should use the m2 plugins (simply go to the Eclipse Marketplace and search for Maven), as they interrogate your POM and set up your dependences properly. You can then concentrate on any compile errors in your code.

You should not point to the jars in the target folder for dependent JAR's since this is where the products of building your project are stored. Performing a mvn clean removes this folder.
To use Maven with Eclipse install the m2e plugin in Eclipse. This makes Eclipse understand the structure of Maven projects.
Once installed you can import your Maven project into Eclipse. I use Import... | Existing Maven Projects for this. But you can also directly import form a versioning system.
During the import Eclipse will set up the Eclipse project to use the Maven dependencies to locate the required JAR's. These are taken from the repository as configured with the used Maven installation.

Related

How to import BOTH Git repository and Maven dependencies to Eclipse?

I am trying to run this tool.
It says that the jar is available on Maven. I created a Maven project in Eclipse and added dependencies in pom.xml. At the same time, I cloned the git repository to Eclipse, but then I have 2 separate projects: one is the Maven project with dependencies and another is cloned git.
Is it possible to combine them? Are there any other ways to install and run a project from github with Maven dependencies?
I checked similar questions but they resolve either Maven or GitHub importing which I know how to do. I am having problems with doing both in one eclipse project.
Thank you.
UPD: I want to inspect Reach tool to see if it fits my research purposes
According to the README it's a standard SBT project, so if you want to import it in Eclipse IDE I would advise to use the Scala IDE (Eclipse plug-in) and sbtclipse (plug-in for SBT).
That being said, the Scala IDE is not maintained anymore so it may be easier to use SBT support in IntelliJ instead.
Anyway you have to clone the git repository locally. From Eclipse IDE you can import it afterwards, see sbtclipse's README.

IntelliJ: Build > Rebuild Project menu item versus Maven clean install

For a Maven-driven project in IntelliJ 2018, when should I choose to use…
The IntelliJ 2018.1 menu item Build > Rebuild Project
The Maven panel’s clean and install Lifecycle items
Under what circumstances is either appropriate?
My situation is a Vaadin 8 application using the vaadin-archetype-application-multimodule Vaadin archetype.
The Question, Does IntelliJ Build > Rebuild Project invoke maven? has a single Answer that says the Rebuild Project does not invoke Maven at all. But no guidance is given on when to use route versus the other.
Well, if you make substancial changes within a pom.xml file (new plugins, new modules within a multi-module project), you'd better run "mvn clean install". I personally never use the "Rebuild Project" within a Maven project. usually I just "make" the project so the class files are updated, or I start a real Maven build to get new / updated dependencies.
The third important option (for me) is the "Reimport all Maven projects" option, which is quite useful if a pure Maven build runs fine, but IntelliJ still thinks that there is something wrong within your project.
When you have a multi-module Maven project and:
Start your tests and application programmatically by IntelliJ (Main.java):
You do not need to use Maven at all, no clean, no install, only Make. And Rebuild when the project gets screwed up.
Click Reimport when you change dependencies or someone deploys a new dependency snapshot to your repo.
If IntelliJ refuses to download the snapshot, then try mvn clean install.
And why would you even do all that? It is faster and more user friendly.
Start your tests and application by Maven in IntelliJ (mvn jetty:run):
You have to install your modules which are as dependencies for the module on which you start your application (mvn jetty:run), because Maven does not use your compiled output for dependencies, but takes an artifact from your remote/local repository. For this case Make/Rebuild is useless, you have to use mvn (clean) install.
If you have made changes only in a module on which you run mvn jetty:run then you do not need to use package/install, but sometimes you have to use clean or Rebuild as Maven does not remove deleted resources.
Make is good for hot-swap - for that reason, it is a good idea to import all Maven projects you develop and on which you depend into a single IntelliJ project. Initial Rebuild comes handy, because without it, Make would compile the whole project instead of only changed classes, then possibly failing hot-swap or it would just take too long.
Or you could just click Make before you run your application, but it could leave some old resources created by Maven in compiled output, Rebuild would take care of that.
You can also configure your app-server to restart/reload when it detects updated files from Make or Rebuild - certainly faster than restarting the JVM or compiling by Maven, but you might like to disable that and use only hot-swap, which is still way faster if you do small changes.
Either way you might want to take a look at Maven Helper plugin for IntelliJ, it will make things way easier in big projects.

GWT maven build eclipse

I had a GWT app, and I wanted to automate its build and deploy system, since I do it manually. But I did not find a way how to build the app from command line, so it can than be automated. I had to click the Google button, then compile GWT project and then click Compile.
I found out that it is possible to create a GWT maven project and that it should then be possible to compile my project from commandline with mvn gwt:compile.
So I created a new project using this plugin. Copied my sources from the old project to this new one.
Now the structure is like this:
/src
---/main
------/java -> here are all my sources including my Project.gwt.xml file.
------/webapp
---/test
pom.xml
Now I have 2 problems.
1. I thought that I add dependencies to the pom.xml, and then when I build the app, it will create the jars and I can use those libraries in my GWT app. I guess 'mvn clean install' should do this, but so far I'm getting compile errors.
2. I did not get mvn clean install to work, so I added all the jars manually again... And then yes! I was able to build the app using the plugin GWT button! So I was thinking that now I can use 'mvn gwt:compile', but it fails with:
Unable to find: "com/company/project/Project.gwt.xml" on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
EDIT:
So I fixed my <moduleName> element in pom.xml, so now it finds the Project.gwt.xml. I'm trying to run:
mvn clean install gwt:compile
But I am getting compile errors. I think, it tries to build my project without the actual dependecies because it tells few classes don't exist, but those classes are part of an external library. (specifically this one). But I have it in the dependencies, so I don't know what more to do.
<dependency>
<groupId>com.github.tdesjardins</groupId>
<artifactId>gwt-ol3</artifactId>
<version>3.0.0</version>
</dependency>
Also in eclipse I had to manually add the jars to my project, so that was why it worked there and not in the command line. So I would also like to ask how to tell eclipse to get those jars and include them to the project, because otherwise eclipse is missing those dependencies and displays many errors.
First I had a problem with <moduleName> in my pom.xml was missing com.company.project prefix before the actual module name.
Then I had errors in my Java files, which was caused by RELEASE version of GWT-OpenLayers 3 library missing some of the features that I previously used by building the JAR from the GitHub repository.

How do I create a JAR with m2e (m2eclipse)?

I'm new to Maven and m2e. It frustrates me that I have to ask this question, but the sparse m2e documentation and Google are failing me.
How do get m2e to build a JAR? I understand that this should happen during the maven package phase, but m2e doesn't seem to do this as part of the build process and I can't find a way to explicitly execute the package phase in Eclipse (nor any other phases that aren't part of the default build).
Thanks.
As long as you have your POM.xml file with the following parameters:
<modelVersion>[a model number eg 4.0.0]</modelVersion>
<groupId>[a group id eg com.myapp]</groupId>
<artifactId>[a unique artifact id within your packages eg myapp]</artifactId>
<version>[the version number eg 1.0-SNAPSHOT]</version>
<packaging>jar</packaging>
<name>[the name eg myapp]</name>
then you just need to run maven build with the goals clean install to create a jar file from your project. You can run maven build by right clinking on the project and going to run > maven build ...
The jar will be created in [project dir]/target
Although "Run As maven install" would do the trick, it can be good
to know that m2e will perform the equivalent of the package phase when doing "Export... Jar/War/EAR file". It seems to understand the plugin configurations too, at least a little bit, and at least for EARs...
As it will resolve artifacts using projects and the m2 repository,
it will also work for "unrelated" modules, as the dependency that resolves to a project is good enough for eclipse to package.
(That is, you don't have to install the unrelated dependency separately, it will be built automatically from the eclipse project.)
I'm not sure I would deploy anything it builds though :-)

How do you refresh maven dependencies from eclipse?

We recently started using maven for dependency management. Our team uses eclipse as it's IDE. Is there an easy way to get eclipse to refresh the maven dependencies without running mvn eclipse:eclipse?
The dependencies are up to date in the local maven repository, but eclipse doesn't pick up the changes until we use the eclipse:eclipse command. This regenerates a lot of eclipse configuration files.
Have you tried using the m2eclipse plugin? I use it with eclipse and it maintains the eclipse .classpath when I add dependencies. It'll also check for updated dependencies.
You generate the special eclipse files with mvn eclipse:eclipse, but once you've done that, you should let a plugin handle the dependencies while inside eclipse.
That's how we do it at my work place, and it generally works well.

Categories

Resources