gradle eclipse dependencies, skipping testCompile/providedRuntime etc - java

Gradle is used to build a simple web application, split into handful of eclipse projects within the same workspace. Gradle script runs tests/creates deployable EAR file just fine. EAR file runs without any issues on a Liberty Profile server.
However, I have problems running it from eclipse (with gradle plugin). The root of the problems seems to be automatic "gradle depencency" management (bunch of dependencies that get injected by "classpass container" org.springsource.ide.eclipse.gradle.classpathcontainer). This thing seems to pick up any dependency, be it compileOnly, testCompile, providedCompile etc. This leads to libs with classes like javax.persistence., javax.inject that are needed for standalone build, but are provided by the application server and are not needed when running from eclipse, being deployed to the app server as part of the application and cause all kinds of errors/warnings.
Is there a way to filter dependencies that gradle eclipse plugin picks up for deployment?

This is a long standing issue with STS gradle tooling. It stems from the fact that gradle-tooling-api doesn't distinguish between provided / test etc. dependencies in the model it produces for the 'eclipse classpath'. At least it was the case when STS gradle tooling was implemented. The tooling-api model has evolved since then, but STS gradle tooling is being phased out and this is unlikely to get a real fix.
That being said, there is a workaround that was specifically implemented for this exact situation.
Go to Window >> Preferences >> Gradle (STS) >> WTP. There you will see a list of regular expression labeled Gradle Dependencies Deployment Exclusions. You can add more expressions there. These act as a kind of global filter. Any jar matching one of these expression will be excluded from WTP deployment assembly.
This may work for you.
However, it is a bit of a crude workaround.
So... I hear that BuildShip which is STS Gradle-tooling's official successor now has WTP support. So perhaps you want to try and switch over to BuildShip. I would assume it deals with provided, test etc. dependencies correctly w.r.t to WTP deployment assembly (if it doesn't you should consider filing a bug report against BuildShip).

Related

How do Maven and m2e-Eclipse-Plugin cooperate

I have some questions about the m2e-Eclipse-Plugin. Version of m2e is 1.6 and the version of Eclipse is 4.5 (Mars).
In my Eclipse-workspace I have a Maven-Project (Java web application) that is deployed on a local Tomcat server.
I really would like to know how m2e-Plugin and Maven work together. If I change a Java-file and save it, the corresponding Class-file in the mvn-target-directory is immediately updated.
Is this compilation done by the default Java-Builder in Eclipse or is it done by Maven ? (i.e. the mvn-compile-plugin does the compilation). If the latter case is true, how is the compile-goal executed ?
Can I configure which mvn-goals are executed if a Java-file is changed and saved? If the compilation is done by the Java Builder, how does the Builder know that it has to copy the compiled
file to the mvn-target-directory
?
I found two posts:
How do Java and Maven builders work together in eclipse?
How do I start Maven "compile" goal on save in Eclipse?
that deal with similar issues. But most of the proposed configuration settings didn't work in my Eclipse.
The compilation in your scenario is done by the Eclipse compiler and not by Maven nor the maven-compiler-plugin. M2E Maps all things to Eclipse internals to handle most of the things needed to work inside Eclipse.
During an initial import of a Maven project into Eclipse using M2E (creating .project/.classpath/.settings) the life cycle will be run till generate-resources and therefore some plugins are run and can create other stuff (things like ANTLR/JAXB generators etc.).
Eclipse handles the correct target folders by reading the pom.xml files and by M2E it is translated into configuration for Eclipse etc. The things you are referencing about configuration is simply not working cause those posts are too old...

Projects which are accessed via multiple (different) IDEs: Ant or Maven?

Is it true that one of the real benefits of Maven is that its projects structure is clearly defined and therefore it can be opened in any IDE that supports Maven?
We develop in a team consisting of 5 people and we use three different IDEs (IntelliJ, Eclipse, Netbeans). I know that I cannot open an Ant project of Eclipse in Netbeans but with Maven this is possible.
Is this really reason enough to use Maven?
Maven and Ant are two different things.
Ant is a build tool while Maven accumulates the functionality of:
resolving dependencies (you only specify the dependencies, and Maven cares about downloading them in the correct version from the default repositories on the i-net, or the ones you specified explicitly)
a build tool (incorporating Ant),
creating distribution artifacts (containing not only the jar/war/etc. file of the project but also dependencies, resources, documentation),
runtime environment (e.g. starting Jetty and deploying your artifact)
unit testing
integration testing
deployment (including signing, incrementing the version, deploying the artifacts etc.)
and more (look out for plugins on i-net)
Maven uses lifecycles to achieve this. You can trigger certain functionality at certain points in the lifecycle. For example unit tests should be run right after compiling while integration tests (e.g. selenium tests) require more setup, maybe initializing a web server and deploying the WAR file.

Java EE deployment in Intellij IDEA

I have a fairly complex Java EE project which can be built fine from Maven. After importing it to IDEA, I had set up a working deployment of the frontend WAR and the backend EAR to a local Weblogic 12c server. The project also have several 'common' artifacts packaged as jars and used by both the frontend and backend artifacts. For deployment, I used the exploded artifacts to save some time on packaging/unpacking, everything works fine till that point.
During development, I edit some Java sources and try to redeploy the updated artifacts to the running Weblogic. I press Shift+F10, choose Redeploy artifacts, I see IDEA building the project, the project redeploys on the server, and more often than not, I do not see any of the recent changes. Even if I choose Rebuild project explicitly and then try to redeploy artifacts after, no changes can be seen on the server. The only safe way to make my changes appear in the deployed artifacts is to invoke maven from the command line calling the package goal, and then redeploying from IDEA. (No JRebel is installed, is being used either in the IDE or on Weblogic, and I'd like to stay that way).
Is that expected behaviour from IDEA? Could this be something specific to our project or something global? Should IDEA be able to discover which projects needs rebuilt and repackaged and then redeploy the EAR/WAR artifacts properly to the server? Does it need any help from my side achieving that goal?
Whats your run/debug configurations? Check this, if not already sois not.
in the quick menu, edit configurations > Run/debug configurations window:
Server tab:
On 'update' action: restart server
Before launch: set 'run maven clean' and 'run maven install'
Deplowment tab
inserts your ear's here.
don't sure this specific answer your question but what I can suggest you is to try configure
weblogic maven plugin
then you can execute deployment from command line / or from IDEA with maven support.
http://docs.oracle.com/cd/E21764_01/web.1111/e13702/maven_deployer.htm
http://www.youtube.com/watch?v=hagaMr6UL6U
Evenif your final goal is to do the whole built process done by IntelliJ build and deployment options I will first try the following:
If your project was set up properly in maven you should be able to load you maven pom.xml within you IntelliJ. All the maven build commands and deployment setting you were doing through mvn command line will show up in your IntelliJ's maven panel in a nice three structure.
If this works out then clearly one of the libraries that are built through your IntelliJ build are not being deployed properly into the right location. You need to narrow down which one of the jars, the ear, or the war has to be affected by a single change you make and then check whether the date of the file is updated in the location it is to be deployed or not.
To wrap up, my humble sugestion though is to use either maven or gradle intelliJ panels for your J2EE projects. As you do achieve the defined goal of having your project built completely through the IntelliJ idea. Also whatever plugin you add to your maven shows up in you idea's maven/gradle panel. It is a fairly straight forward approach and you achieve a powerfull and flexible deployment and build tools within IntelliJ like your wanted.

Releasing from development into production in maven

I'm confused about the use of maven in development and production environments - I'm sure it's something simple that I'm missing. Grateful for any help..
I set up maven inside eclipse on my local machine and wrote some software. I really like how it's made things like including dependent jars very easy.
So that's my development environment. But now I want to release the project to production on a remote server. I've searched the documentation, but I can't figure out how it's supposed to work or what the maven best practice is.. Are you supposed to:
a) Also be running maven on your production environment, and upload all your files to your production environment and rebuild your project there? (Something in me baulks at the idea of rebuilding 'released' code on the production server, so I'm fairly sure this isn't right..)
b) use mvn:package to create your jar file and then copy that up to production? (But then what of all those nice dependencies? Isn't there a danger that your tested code is now going to be running against different versions of the dependent jars in the production environment, possibly breaking your code? Or missing a jar..?)
c) Something else that I'm not figuring out..
Thanks in advance for any help!
You're supposed to have your code under version control (and you never "upload" files to another machine, you "download" them from the Version Control System if required).
You're supposed to package your code in a format (a WAR, an EAR, another kind of bundle) that can be deployed on the production environment for execution. Such bundles typically include the dependencies. To build more complex bundles, the Maven Assembly Plugin can help.
Maven generated artifacts (JARs, WARs, whatever) should be shared via a remote repository (and thus deployed - I mean mvn deploy here - to this remote repository). A remote repository can be a simple file system served via a web server or a more advanced solution like Nexus.
Development is usually done using SNAPSHOT dependencies (e.g. 1.0-SNAPSHOT). At release time, you're supposed to change the version into a "fixed" version (e.g. 1.0) and some other bits from your pom.xml, run the build to check that everything is ok, commit the modified pom.xml, create a tag in the VCS, promote the versions to a new SNAPSHOT (e.g. 1.1-SNAPSHOT) in the pom.xml, commit the new pom.xml in the VCS. The entire process require some work but this can be automated using the Maven Release Plugin.
On the production environment, get the artifacts to be deployed from the remote repository and deploy them (some projects automate the deployment to the production server using Maven but that's another story).
Of course, there are variations around this (deployment to production is most of time company specific) but the general idea is there.
You need to look into the Maven Assembly Plugin and the Maven Release Plugin.
When building artifact you usually state what scope the dependency has. In default scope it should be packaged in your archive. If you do not want it, use scope "provided" - in such case you have to prepare runtime environment providing the dependency. It's generaaly a bad idea to rebuild a package only for deployment.
As for deploying, you can use maven's antrun plugin to copy files locally or via scp .

Development Environment Java 6, Maven 2.x, Eclipse 3.4.x, JBoss 5 and JBoss Seam

I have to organize a development environment where I can run Maven projects with JBoss Seam, IDE eclipse 3.4.x and deploying to JBoss 5.
The projects that will run on this environment are based in Java 6, EJB3 and JSF1.2. The environment has to support hot-deploy.
I used to work in a development environment with Sysdeo Plugin to make Tomcat run all my applications - I've rarely used EJB (only for MDB's).
So I would prefer an environment similar to this.
I'd like to know what you guys use for the kind of architecture (what kind of eclipse plugins - if they work fine, things like that)
The thing I really didn't get right is why my Maven2 project with SEAM as a dependency packaged as EAR doesn't appear in my server (in Eclipse Ganymede - tab servers) for me to make deploy (right click - option Add and Remove Projects...).
Do I have to include an specific project nature to make my Maven2 EAR project visible to my JBoss AS included in my Eclipse Ganymede?
Seam doesn't appear to go well with Maven2. I'm facing some problems to make they work together - some dependencies appear to be missing and I have to put some extra files in some special places like seam.properties and components.xml with some special contents.
I feel like forced to use seam-gen and Ant. Too bad!
Not sure if this is helpful to you, but but we run the following
eclipse as IDE
mercurial for source code management
merclipse mercurial eclipse plugin http://goldenhammers.com/merclipse/
maven for builds (and m2eclipse)
mylyn with bugzilla for issue tracking
tomcat as application server
hudson for continuous integration http://hudson-ci.org/
reviewboard for code reviews http://www.review-board.org/
sonar for code quality metrics http://sonar.codehaus.org/
proxmox VE for virtualization http://pve.proxmox.com/wiki/Main_Page
Most things run on separate virtual machines to keep interference to a minimum. Proxmox VE is a breeze to setup (15 mins and you are running).
Hudson monitors the repository and automatically builds and tests each push.
If the war build is successful it is automatically (re)deployed (using a hudson plugin) into Tomcat and restarted.
I cannot recommend these tools enough.
HTH
I am currently working on the same environment you asked for, with the only difference I am running the app on a tomcat 6.0.18. I prefer to use tomcat 'cause it's so faster to run, and I don't use EJB for now.
Eclipse plugins :
maven : m2eclipse.codehaus.org
jboss tools : www.jboss.org/tools
web tools platform for hot deploying : www.eclipse.org/webtools/
I took the Eclipse Java EE version, I don't use seam-gen to create the basic architecture.
I don't have so many problems with this environment, sometimes the hot-deploy doesn't work and I have to manually clean files.
The only problem I had was with the separation of my app in two modules : eclipse wasn't doing the job well (not taking the last package of one module while building the other one), and I discover the option "disable workspace resolution", which works fine now.
Works fine. Hope it will for you.

Categories

Resources