Project configuration for IDEs use same code formatting - java

Issue
It is common in many projects that each developer uses the IDE of their preference, where the most common are Eclipse, Netbeans and Intellij.
In this case, they use that shortcut for formatting the entire file, and code formatting conflicts often occur, which makes revision implementation very difficult.
I've heard of plugin (EditorConfig) and XML config files to solve this issue and keep a unique formatting for the project, but have not yet seen this being used effectively.
Question
Is there a common practice for solving this problem, which is valid for these major IDEs? If possible, add an example configuration to the answer.

In terms of Java, there's Checkstyle
Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.
And plugins exist for both Maven and Gradle (which I'd recommend using for any Java project)
You may also integrate tooling into your source control that performs these tasks, but it would be preferred that developers check formatting before pushing

Related

Advantage of using checkstyle rather than using Eclipse built in code formatter?

Is there any functional advantage of using checkstyle instead of Eclipse own code formatter? In either case, we would add some custom rules, but it would largely be based on Sun's java code convention.
Here are some advantages for using checkstyle:
portable between IDEs. If you decide to use IntelliJ later, or you have a team using a variety of IDEs, you still have a way to enforce consistency.
better external tooling. It's much easier to integrate checkstyle with your external tools since it was really designed as a standalone framework. You can plug into your SCM as a pre-commit hook, or into your build tool, quite easily. Using Eclipse style convention you would need to write or locate a plugin to do the same thing.
ability of creating your own rules. Eclipse defines a large set of styles, but checkstyle has more, and you can add your own custom rules.
The advantage of Eclipse formatter/styler, of course, is that it's already built into the IDE, so if your team is already standardized on Eclipse you can get everyone up and running very quickly. But using checkstyles gives you more options.

Creating new class versions

I'm currently working on a project. I've been running into a few issues with the e-mail functionality, I've made multiple attempts to fix the issue and the latest seems to have fixed the issue.
For each rewrite I've created a new class to hold the new code. This doesn't seem to be the best solution as each time I have to go through the code and track down the references to the class and update them, with each rewrite only the code for the actual sending of the email has changed, function inputs and names have been consistent.
I've looked up versioning but this hasn't been particularly helpful in providing a solution either granted most likely due to my own lack of knowledge on the subject. So here is what I'm looking for: to have one instance of the class with multiple versions preferably without all the old code in it to aid in reading. But I want access to the old versions so that if a function/feature was there previously and wasn't built into the current version I can see how it was implemented.
Versioning is exactly what you need here.
Have a look here, which gives you a brief introduction to subversion, one of the most popular versioning systems. You can either set up / use your own private subversion server, or if you project is open source use a number of free providers (such as Google code) who will provide versioning for you.
Other versioning systems exist other than subversion, such as git, mercurial, etc. - but subversion is arguably the most popular and a good starting point.
Are you using any IDE? Eclipse/Netbeans store the history of your file updates and you can always compare/replace from history.
Note: This is not a replacement of version control in any way and I would highly recommend that you explore open-source version control solutions. This would help you in the long run
Mercurial is the way to go. Seemless merging and integration with java and popular IDE's like Netbeans. You can't go wrong. From the very beginning of my programming experience I learned how to use Mercurial in a day.
Use version management tool likes as SVN or CVS.

What is the current state of tooling for Scala?

Over the past year, I've heard an increasing amount of hype regarding the Scala language. I know that there are several existing projects that have plans to integrate Scala support with IDEs; however, it isn't always clear how good the integration really is.
Do they currently support Intellisense as well as Eclipse and Netbeans do for the Java language? Do they support instant verification as well?
I can't personally speak to the stability of the IntelliJ or NetBeans plugins (though I have heard good things), but the Scala IDE for Eclipse just recently made a new release with Scala 2.7.4. Architecturally, this release is quite different from the previous ones in that it uses Equinox Aspects, the officially supported mechanism for extending JDT (and other cross-plugin extensions). Whereas before the Scala plugin had to literally hack into the JDT internals using private APIs and reflection to trick the system into behaving properly, now it is able to simply declare its extension points and let the system do the rest. It's hard to even describe how much more stable this makes things. I'm not saying that it's all sunshine and roses yet, but if you've tried and rejected the plugin in the past (as I had), it's time to give it another look.
As for how it stacks up feature-wise, SDT doesn't have any refactoring support (IntelliJ has some basic stuff like "Rename"), nor does the editor do some things like "Mark Occurrences". However, it has a significantly better Outline than NetBeans, better compiler support than IDEA, and very good semantic highlighting. All three plugins support content assist (or "intellisense", as Microsoft calls it), but none of them are particularly reliable in this area just yet. The Scala IDE for Eclipse is the only one to support incremental compilation (alla Eclipse's Java tooling).
My advice: shop around. Try all three and see which one works the best for you. From what I've been hearing, the Scala IDE for Eclipse has leap-frogged the competition with its latest release, but the others have shown such consistent stability and steady advancement that you can't count them out just yet.
Here's a similar question:
Which is the best IDE for Scala development?
In my very short experience with the Scala IDE for Eclipse and the Scala Plugin for Netbeans, it seemed like the Netbeans plug-in was a little more solid than the Eclipse one.
With the Scala IDE for Eclipse I was having problems with running a Hello World-type Scala object, and sometimes the syntax highlighting would start acting up. Then, I tried out the Netbeans plug-in, and it seemed to be more functional than the Eclipse one.
I haven't used either Scala IDE plug-in much in-depth, so I can't speak out of a lot of experience, but just from my initial impression, the Netbeans plug-in seemed a little bit more stable than the Eclipse one.
Currently, all three main IDEs are at roughly the same level of support.
IntelliJ - the plugin has fits of not working at all, but is otherwise quite good. The underlying platform is sluggish (at least in linux) since v8.
Eclipse - the plugin is receiving a lot of support and is under very active development.
NetBeans - IMHO, the plugin works a little better than the Eclipse one, but not being able to run arbitrary files is a major downer.
All of the above suffer from being unable to parse the AST in all contexts. It is quite easy to confuse them by mixing in traits with implicit defs, for example. No IDE can be trusted when it advises of a syntax error. Fall back to the compiler to be certain.
I'm quite happy using IntelliJ IDEA 8.1 and its Scala plugin and can recommend it. It even has a roadmap that you can influence by voting your favorite missing features :) I don't have experience with the Scala support of the other IDE's, unfortunately.
I'm using the Eclipse Scala plugin. Its pretty good but not at the same level as the Java tooling.
AS for intelliJ, no idea.
But between Eclipse and Netbeans, I must say Netbeans especially if you are not willing trade maven for sbt and you want an IDE that does not get in the way of maven.
Netbeans maven support is just way too good.
The Netbeans scala editor seems to work quite nicely as well.
I care not for the integrated scala development kit in netbeans or the compiler plugin, or any such helpers. From netbeans I expect only tthree things:
(a) Do not get in the way of maven and let maven run my build
(b) Give me a decent editor
(c) Let me drill down from my .scala files into the source code of the libraries referred by my maven dependencies.
And Netebeans is able to deliver all three quite well, I belive, even if at times it feels a bit too slow.
What I can say is that
(1) You do not run into any compilation issues since the task is up to maven.
The maven compiler plugin is a bit too slow. But compiling scala vs java is always like that, painful. Still if you've tried GWT compiling java to javascript is more painful even.
(2) Netbeans figures out the source code to you maven dependencies flawlessly and you can drill in into the most obscure sacala operators, such as the CSS mappers of lift.
As for eclipse, eclipse maven integration has always been nasty.
Netbeans maven integration can turn very sour if you have a big project with too many dependencies and modules. Then the check for external changes done by netbeans is just horribly slow. That is the downside of netbeans.
However, if you are and SBT fan ... well, maybe then answer might be something else.
But for me, since maven has become the thing it is today, I never want to go back again to those "web application project", "library project" etc... wizard like options that you have when you create a new project in the IDE.
I simply want "maven project", and please figure out what my output artefact is by reading the pom.

What do you use for a complex build process? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am trying to revamp our build process, which is currently a gigantic Ant build.xml that calls into other ant build files and executes several Java classes to perform more complex logic that would be impossible/scary to attemp in Ant.
Background:
experience in Java and Ant, some Groovy
Windows platforms
Goals:
run as a combination of command line cron and when a servlet is posted to
as simplified as possible, fewest languages and bouncing between techs
I need higher level logical power that a language like Java provides and Ant is pretty easy and we use the filtering to override default properties files for different clients. Mostly I'm wondering if there is something other than Ant/Java that people use.
Except the Ant you mentioned and the scarry make/autotools, the mainstream tools are:
SCons
Jam
CMake
Maven
I use SCons, because it is python based, well-funded and elegant.
Jam seems to be the most pragmatic one.
I don't know too much about CMake.
Maven may be the choice for you as it is Java centric and more high level than Ant.
More you can find at wikipedia: List of built tools
If you pursue Maven, then you will have two problems: a complex build and learning the f#*#ing "magic" of Maven. Maven just makes the problem worse because it is obtuse and overly-complicated.
I inherited a legacy Maven 1.x build at a large Fortune 500 company. I used Maven 2.x by choice on many other projects in recent years. I evaluated Maestro, in hopes that it might make Maven tractable. My conclusion, like many other peoples' (check the 'net), is that Maven is a big step in the wrong direction. It definitely is not an improvement over Ant.
I have used Ant for MANY years, including writing a large open-source library of Ant helper scripts. I have also extensively used its .NET cousin nAnt. However, Ant has two major failings. One, XML is simply not the right place to be doing build tasks. Two, Ant and XML do not scale well to large, complex builds. In fact, I have written a lot here at SO about my experiences in that arena (and with Maven).
Industry leaders have concluded that a build is just another application, and should be approached using general application tools. However, since it involves system-level and cross-platform functionality, most development languages/platforms are not properly suited (which includes Java, and therefore Ant and Maven). That also excludes .NET.
I spent two years looking for an alternative, and I found it: Python. It has the right combination of system-level access, cross-platform portability, simplicity, readability, power, robustness, and maturity. SCons, buildbot, setuptools/easyinstall, and base Python are my current target platform for the build process. When necessary, integration with Ant, Maven, and any other such tool is easy. Meanwhile, I can use these tools for the core of any build on any platform with any source language. No more roadblocks, no more crazy complexity, no more supposedly-helpful "declarative" scripting, no more black-box f#*#ing "magic".
If you can't switch to Python, then try Ant + Ivy (at apache.org). It gives you Maven's cool repository without most of Maven's evils. That is what I am doing as well, where necessary and suitable.
Best wishes.
Also take a look at
Gant
Gradle
While more general purpose build systems like SCons are very powerful, the Java support is somewhat limited in comparison to systems specially tailored to build Java projects.
I like using Rake as you can fall back on the power of the whole Ruby language and it's framework library when needed.
I use Ant, taking advantage of its macro feature. If you layout your project in a consistent mannner, you can eliminate a lot of the duplication by writing macros.
I've been building up an Antlib containing macros and custom tasks that I reuse across multiple projects.
Alternatively, some people swear by Maven. Other people just swear about Maven.
I use Maven, not just for build, I also use their release/dist plugin.
In a pair of commands I can have code that was in a source control to build, package and release.
The release plugin handles updating the version numbers, dist handles how to put everything together and zip it.
Ant looks hard when compared to Maven. Sure there is a learning curve with Maven, but reading a pom.xml is far easier than reading a build.xml.
Maven needs to be far less verbose.
I like Ant but only if you spend the time to write your own Java plugins to encapsulate complex actions. It isn't hard but unfortunately most people try to write their logic in XML w/the ant-contrib stuff. I think this is a huge mistake.
I've heard good things about rake and the groovy tools (mentioned in another comment) but I've got no experience with them.
If you're trying to script together several steps in a life-cycle you might be better off using a process automation based build server like AnthillPro (Cruise, BuildForge and Electric-Commander are the others in this space).
Another place to ask this kind of question is the CITCON mailing list. CITCON is a conference on Continuous Integration and Testing and the associated mailing list has turned into a really great community around these kinds of topics.
(I'm an organizer for CITCON but a labor of love not a profit maker. It really does have a really helpful mailing list. If I was pimping something for money it would be The CI Guys. ;-) )
Stick with Ant since you're building Java. I've mixed Ant/SCons for some JNI work, but in general I'd stay with Ant especially since you've got an existing build setup in Ant. Porting to Maven will be like shoving a square peg through a wall with no holes.
Embrace your custom Java logic for any and consider writing proper Ant tasks instead of executing external Java code. I solved some very complex parts of our build process by simply extending Ant to do exactly what I needed, ex. managing icon resources for a large gui project or injected subversion information directly info jar manifests (thank you SVNKit)
I'd go with Ant any day of the week.
It's not perfect; XML is very verbose and implementing any logic at all is almost impossible, but even the most junior engineer on the team can at least understand what the ant file is doing within a day.
Complex logic can be refactored using java and integrated in ant, if you so wish. Ant gives you all the power of java:)
Dependency resolution is difficult no matter what system you use. With ant, the best solutions seem to be either a lib directory in which all your jars are stored, or an internal web server from which the libraries are copied at build time.
I also have some experience with both Maven 1 and Maven 2. That experience left me with the feeling that Maven is awesome for hobby projects, but can have complications for software you need to maintain over time.
I see two important problems with Maven:
Any dependency you import using Maven may change over time without you knowing it, resulting in weird problems.
You import the licenses of not only the software you import directly using Maven, but also the licenses used by the libraries which are indirectly imported
In short, I dislike the fact that the build depends on the time it is started. That can be a true problem when producing a bugfix release a year after the production release.
These problems can of course be managed (maybe using a nexus proxy) but you need to consider them before rebuilding the build system. At my company we decided to use Ant for all new project and try to port maven 1 and 2 to ant whenever the occasion presents itself. It's just too difficult to keep it working.
My advice, if you and your team know how to deal with ant, try to refactor your ant file and don't jump on some other build tool. It just takes too much time to get it right; time you could spend making money and surviving as a company :)
I use Rake everywhere I can. Where you need to build java code you might use it with jruby, or look at something like: buildr
We use luntbuild. It's a web app that's very easy to use. It will check out from CVS/SVN, automatically increment the version/build number, execute build tasks in ant scripts and tag your repository with the new version. Can schedule automatic builds, have it email you or contact you via IM, also has security and build dependencies.
We're still using version 1.2.3 but I see it's up to 1.6.0. It just works.
http://luntbuild.javaforge.com/
EDIT: Re-reading your question I see now that you're looking for something to replace Ant. In our case Ant is not really a problem. We have projects setup in Netbeans, which uses Ant for building and we just have to implement some hooks into the existing scripts provided by Netbeans which is very easy to do.
EDIT: Looks like you can call Ant from Groovy. That would be nice because then you can re-use all the tasks that already exist for Ant.
http://groovy.codehaus.org/Using+Ant+from+Groovy
Try FinalBuilder
It provides a GUI interface to whatever your build process may be and has a native action for almost everything, plus an action studio where you can create your own.
With a bit of planning can be very streamlined.
I have to add to these one solution that I find I can't live without ... its called Hudson. It only takes a few seconds to setup and you can usually get away with most of whatever your existing ANT files are already doing.
Additionally, Hudson provides a great way to "cron" builds, execute test cases, and generate "artifacts" (e.g. build products) in a way that anyone can download.
It is hard to capture all that it can do for you ... so just try it out ... you will no be disappointed.
Maven is really good choice to do large builds...in the majority of the cases where it doesn't work is very simple. The people misunderstand the concepts of Maven. If your are working with the "maven way" you will end up with smaller modules which gives you a better architecture in your software. On the other hand things like Hudson will support you in reducing build times by using Maven, cause Hudson supports to build only changed modules which is not supported by any other build tool. The problem with Maven is to learn and understand the concepts of Maven for example the structure of a project(folders etc.) or only a single artifact etc. The build-cycle will support you in different areas: compiling, packaging, deployment and release which is not supported by other tools (only if you implement it by hand...I've wrote many large Ant scripts to reach this)...Other problem like changes over the time are caused by ignoring the best practice and pin pointing versions which are used.
I use mainly Ant, but Maven is also a good tool. With ant you can do anything you want.
At our company, we created a general purpose ant builder that does a lot of things: Build, Compess images, minify, generate documentation, pack files.. It is open source and we are open to improvements. You can get it here:
https://github.com/edertone/TurboBuilder

Is Ant still the best choice for a Java build tool? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
From my small amount of experience, I've only used Ant as a build tool. Are there any other projects which are better, and why?
Maven
It is much better than ant because for most common tasks you don't have to write a complicated build.xml, maven has very good defaults and it's all convention over configuration.
It has also a big central repository of libraries and it's very easy to configure it to, like, "use latest stable commons-whatever". Maven will then download the latest stable version for you (no more checking in jars into VCS) and if a new upstream stable version is released, it will download it as well. Of course, it's just as easy to lock it to some specific version should you need that.
It is also well integrated both with Netbeans and Eclipse (m2eclipse plugin) so the IDE honors whatever settings (including dependencies) you declare in the pom.xml file.
There are also some downsides to maven: some plugins are rather poorly documented, integration with both IDEs is not really perfect, and that in different ways, some error messages may be hard to understand.
Ant is still a major player. In my experience, it is dominant. Plus, with Ivy, it handles some of Maven's strengths. IMO, Ant will become a framework for other tools: XML is too rigid (see link below).
Maven 2 is also a major player. I know people who quite like it and bristle at criticisms that were true for Maven 1 (it has come a long way).
Groovy is offering some cool stuff in the build space, because they build on Ant. Gant is used in Grails, but may be subsumed into Gradle. These can be used for Java as well.
At the risk of pimping my own blog, here is a post about Gant and Gradle. Here is a link to the very current debate about their future.
in the enterprise, ant is still the entrenches player. dependencies don't change fast. unlike open source projects that keep moving to fairly newest version of dependent jars, MOST enterprises try NOT to change their dependencies too fast. Given that, maven's advantages are NOT too much compared to ant.
Then again, if you want some of maven's features, ant folks have ivy (http://ant.apache.org/ivy/) for the dependencies feature.
IF you want to continue using ant, get hold of "ANT IN ACTION", 2nd edition so that you can use ant to the best productivity.
Good luck,
Some people like Ivy, which is a dependency managing thingy for Ant so I suppose that people coming from an Ant background will like it.
Others like Buildr. It's a JRuby thing, so if you can juggle Ruby and Java in the same projects, then I suppose it'll be interesting.
Personally, I just use Maven. It's easy to whip up a default pom.xml file and have all the build commands at your disposal. And when the project grows, you already have the infrastructure in place for running plugins and adding dependencies.
You also have Gant. Gant is Groovy + Ant, you can write your tasks in plain groovy and you can also call any ant task. If you are a Java shop and want to reuse the ant skills you have but dislike XML, I recommend Gant, it is ver easy to setup and you can embed it in ant (and also call gant from ant).
I really like SCons, which is a build tool whose configuration files are all just Python scripts. This will appeal to anyone who knows Python or similar scripting languages. SCons is designed to work well with Java as well as C/C++ and other languages, and I've been very satisfied with it in the past.
Because SCons files are written in Python, you can write arbitrary Python code if you find yourself needing to do anything special. However, if you're completely unfamiliar with Python, then there will possibly be a higher learning curve than trying to extend Ant or something similar to do what you want.
Maven2 seems to be the up and coming thing.
For our projects however we are migrating back to ant wherever feasible.
Maven2 requires quite a bit of knowledge to get it exactly the way you want, and Maven2 versions seem to handle classpaths differently.
And it is a pain to check all licenses included in the dependencies of the dependencies which may get drawn in.
And may have a slower start-up time, as you need to figure out the dependencies yourself, but at least it's easily readable. No magic going on here :)
If you do use maven, give a thought to an internal repository like Nexus. That way your software is not dead if some libraries decide to go away from the net*.
*We got burned with maven1; the ibiblio maven1 repository redirects and maven1 does not support redirects :(
I would urge you to start with your requirements when considering the right tool. Each project is different, the tool you use should reflect the problem space not the fashion.
That being said, I think for general use ant is still probably the best general tool for building java applications. It is often used effectively with other tools for dependency management but there we go again skirting off into a solution without a problem.
The very good news, is that if your process are good switching build tools is a fairly painless process - lesson - start with a good process scaled to the problem at hand.
You will find already some answers in What are some good java make utilities?.

Categories