Trying to migrate an ant project to the maven project and was able to use translate to the maven project feature of the eclipse. Though I have an idea of working with maven projects so far, but still would like to know if there are any best practices to follow while migrating it.
Also, would really appreciate if anyone can help like how to set up the same on bamboo that would be ideal for all the working developers.
The steps achieved so far are :
Created pom.xml with all the required jars and repositories.
Created a local .m2 folder with dependencies present and installed.
I would like a meaningful transition from ant to maven. I know how things work on local but when it comes to deploying it to bamboo, I am a bit confused with so much distributed information on the internet.
Any specific leads would be really helpful
Related
I am creating a java project in IntelliJ (without maven or grandle). The project uses an external library, whose .jar file I’ve put into a /lib directory. After that I had to select at the /lib folder “add as library” to use it.
Now I want to push the project to GitHub, so that some people (who are using IntelliJ as well, but in different versions) can use the project.
Now my question:
Is there a way, that they do not have to do the step “add as a library” themselves?
My first idea was to push also some parts of the .idea folder to GitHub, but I am not sure which ones to push and if that could actually work (especially with different versions of IntelliJ).
Do you have any idea how to solve this issue?
If you are using only IntelliJ for building the project, then yes, you should push the .iml files from the .idea folder (or where they happen to be), since they contain the dependencies configured in IntelliJ.
Note, that projects with multiple contributors typically use a build tool like Maven or Gradle.
This is a special build requirement, which I would use Gradle for. With Gradle you can look up a given folder, like /lib and use all .jar files as dependency.
See Gradle example about exactly what you want.
IntelliJ is handy when you do something simple mostly for learning, but if you want to be a professional one day I highly suggest looking into Gradle. It has a learning curve for sure, but you can achieve such simple tasks like this in your question relatively simply. And as you seem to know, pushing .idea to the repository is really not the nicest thing one can do :)
Just a small additional note: Gradle solves the "different version" problem by including a "Gradle wrapper" inside the repository, so everyone cloning the repository will have the same copy of Gradle as well, so the same build process is guaranteed for all contributors.
Also, when I started programming I downloaded the dependencies and used them as jars. But if you learn at least Maven, and your dependency is uploaded to a repository like Maven Central, you can just paste a line of code into your pom.xml (Maven) or build.gradle (Gradle) and you are good to go :)
I've been working on a Java project using Gradle in Eclipse that builds on my local machine and works just fine. I want the project to be available to a team of developers via Git, but after creating the repository and trying to build on a different machine using both IntelliJ and Eclipse, I'm realizing that there are some challenges. For instance, it seems like there need to be minor changes in build.gradle. Or in IntelliJ, JDK 1.8.0 must be specified for java.util.stream.
My goal is to create a project that allows a team of developers to simply clone the repository, use any IDE they want, build the project and begin contributing right away. Has anyone attempted to do this before with Gradle? What are some tips or insights? Is Gradle a poor choice for this? How can I standardize the build, libraries, etc.?
I'm following this tutorial: http://spring.io/guides/tutorials/rest/ to get familiar with spring/REST. However, the git repo (git clone https://github.com/spring-guides/tut-rest.git) has many individual java projects each with their own gradle build. I'd like to edit the code in Eclipse, as that's the whole point, but this hasn't proved trivial.
So far, I've created a general project for the git repo, and then separate java projects for each of the folders from the repo, linking the source in my java projects to the source/test folders in the repo. This has worked great except that I don't have the spring jars in my dependencies for the java projects, I get a ton of errors as well as lose the nice autocomplete of function names, etc.
What is the correct way to fix this? It seems like there isn't a good way to install the jars for spring in each java project without using maven or some other build tool, which seems redundant and inefficient since I can build the source from the repo project. If this is the case, should I make a build for each separate project even though the idea for the tutorial is that they each come with gradle?
Thanks for your help, and please excuse the slight open endedness of it--I'm not sure I'm on the right track.
Is there anything already out there that would help with either / both of following?
Perform a Maven install when a file within that module changes
Perform a Maven install on the module and its dependencies if they have changed
I'm pretty sure I've heard of a Maven option to build dependencies as well but struggling to find anything from Googling...
Perhaps this isn't going to be Maven specific but instead involve a file watching tool that is OS specific, if so I would be interested in hearing about tools for Windows (XP).
Even though the answer comes late, I was looking for the same thing and I found https://github.com/rzymek/watcher-maven-plugin. Maybe someone else will be looking for the same thing.
I tried #Adrian's solution, but I couldn't get it working.
I found this maven package, https://github.com/fizzed/maven-plugins#watcher-fizzed-watcher-maven-plugin, that will watch for file changes, and I was able to get it working pretty quickly.
To building a module and its dependencies, use:
mvn -pl :module -amd
Automated builds are usually triggered from a version system like subversion or git.
Then you can use continuous integration tools like Jenkins.
There's also mvn reactor:make-scm-changes, which detects what modules have local changes vs. the configured scm system.
Perhaps the reason I stalled learning Java until now is because I HATE how Java handles external libraries. I'm stuck keeping them in one place, adding them individually, fixing problems with versioning and every time I move/rename them, and copying and writing the classpath over and over each time I release a Java application.
There has to be an elegant solution to all of this. I keep all of my libraries (regardless of task, platform, or other) in their own little folder inside a "lib" folder in my development folder, kind of like this:
Dev
-lib
+JS-jQuery
+Flex-Degrafa
-Java-Xerces
+Xerces-1.2.3
+More libraries
I can use either Netbeans or Eclipse for Java dev, but none of them provide a very streamlined (and not to mention idiot-proof) way of managing all of these.
A nudge in the right direction or an online article/tutorial on this would be greatly appreciated.
You can either use Ant + Ivy or Maven to manage your library dependencies.
If it is only dependency management you're after and you're happy with the rest of your build process, I would use Ivy, as it can unobtrusively manage your dependencies, leaving your existing build process intact. There is a plugin for Eclipse called IvyIDE that contributes your dependencies via a classpath container.
Maven 2 has a steeper learning curve but provides a much richer set of functionality for building your projects and Eclipse integration through m2eclipse or IAM.
Personally I use Maven as I have a large number of projects to work with and Maven is particularly suited to efficient development across lots of projects.
Have a look at the introductory documentation to see what works for you.
Ivy Tutorial
Maven Getting Started Guide
Netbeans 6.7.1's Maven support is quite good and comes out of the box with the IDE.
The Eclipse addon was frustrating enough that I gave Netbeans another try.
A third choice besides ChssPly76's options is to use Ant with the Maven Ant Tasks. I don't know if I'd call any of these solutions particularly "elegant," but they do spare you the need to manage your own lib/ directory and classpath variables.
If you're working on Linux you can install Java libraries with APT or RPM.
Otherwise, I normally check precompiled JARs into a lib directory in my project's version control repository and make sure the names of the JAR files include full version information. E.g. lib/foo-1.5.6.jar, not lib/foo.jar.
To avoid having to manually set the classpath before running your app, you can set the classpath in the Manifests of the JARs themselves to define the dependencies of each JAR file. The JVM will follow all the dependencies when loading classes.
Maven is often more trouble than it's worth, but the ability to open a maven project directly into IDEs such as IntelliJ is excellent. For example, IntelliJ will download all dependencies and have them available without having to run a build first, or an mvn command and then a project refresh. It also isn't necessary to re-generate the project every time a dependency is added. I work with a number of Eclipse developers who switched to IntelliJ for this alone.
However, one shortfall of Maven is that many libraries (or versions of libraries) are not available on public repositories. Therefore it is often necessary to set up a local repository such as archiva. In ant, it would just be a matter of adding it to the lib directory in the repository.
Maven can also attack when you need to do something that maven doesn't directly support via a plugin. What would normally be a few lines of ant can often turn into a morning's worth of work.
Finally, buildr is an excellent way of using Maven's dependency management and plugins, while also supporting ad-hoc tasks.