1/10/12

Maven distinct dependencies ?

I wonder if it is possible, to stop Maven downloading old libraries and use only distinct versions (prefering the local repo and the versions where i downloaded Javadoc and sources manually).

For example using JUnit dependency versions 3.8.2, 4.8.1 and the newest 4.x, but never <3.8.1, 4.5, 4.6-Snapshot etc.

Background: I have my actual projects and local repo on first drive (SSD) with limited space.
If i try an maven archetype to start a new project (often for learning a new theme), maven likes downloading i.e. junit 4.5
but i don't like to edit the pom manually looking over my local versions, thinking about compatibilties
and i don't like to purge and download the prefered dependencies again and again.

Are there any tools, plugins, settings or best practices to get this going ?

What i tried so far...
  • going Offline doesn't help cause my preferred IDE offer download manually only for doc+src

        => "Could not resolve dependencies... "

        "The repository system is offline but the artifact ... is not available in the local repository."
        Don't try this at work / production !
        My dependencies were not loaded after turning Online again :-( restart of netbeans doesn't fix until i reboot.

  • One practice is (Netbeans) in context menu on project explorer "Remove dependecy" and "Add as Dependecy.." from context menu in windows with local repository tree:

    Use menu Window | Other | Maven repository browser to get this :

    Then in window "Project explorer" i remove the disliked dependency not necessary

    In window "Maven repo..." select the prefered version from local repo. and add:

    So finally i get the version i prefere in the project with javadoc and src:




     
  • Best practice (Small solution) for me is now this:
    - create the pom using an archetype
    - add <dependencyManagement../> decribing the prefered dependency in the top of the pom
    - add <scope>provided</scope>
    - optionaly you can add the <exclusions.. />
    - remove the conflicting <version../> tags in the generated pom
    - the <dependencyManagement../> section i will use for copy/paste in other projects

    Example for junit:
    <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <!-- http://maven.apache.org/plugins/maven-enforcer-plugin/rules/versionRanges.html -->
                    <!-- <version>[4.8.2,)</version> use 4.8.2 or higher version -->
                    <version>4.8.2</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>

    Remove the conflicting dependencies by editing the pom manually in the lines marked by Netbeans ;-)



    Or when use "Add Dependency" you then see the tab "Dependency Management" offering the prefered distinct dependency and version:


  • Greater solution (hopefully) ?

    - create a parent/master pom with <dependencyManagement../> of prefered artifacts
    - use the from archetype generated pom as module or child-project
    - use the master pom for grouping dependencies with <packaging>pom</packaging>
Some of the stuff i find usefull for this theme: :
Maven-Model (look for dependencyManagement under project)
Maven: The Complete Reference, Chapter 3.6.1. Grouping Dependencies

Long time no post...

Things at work changed the last year. So priorities changed.

Becoming a member of a new team that is using Linux, C, Java, jsp, little php and much Oracle pl/sql, there were plenty of things to learn for me, coming from Microsoft (old world) C++.
So there is a little time to read the daily feeds that i prefered.
Less time to learn Scala and other interessting things like Android.
Lesser time and motivation (does anybody ever read the last posts ?) to write on the blog.

But Scala (language) has getting greater, mature and stable this last year i think.
There are some themes were it is possible to mix up the Java know how,
i need for work, with new technics i like to use with Scala.

Another point is english is not my first language. Like to guess what it is ?
(Are comments working here ? Hmmm ~:-|, i'm still learning Wordpress...)

Reading, hearing means no problem, having eight years of english at school and several lessons on university,
but if you have no great traveler background and not some years of study or practice in foreign countries it is difficult to
find the right words speaking and of cause writing in english.
But being a long time it-professional (hopefully) i'm used to read books in english.
When reading on the internet, i don't distinguish between english and native language.

So i will retry to write something useful (i hope) here. You can beat me, if i get ready to activate the comments one time...

But now i think it's better going one step back and install a local version of Wordpress and explore first ?

2/14/11

Doing some Coding Katas in the meantime...

For some time, i tried to learn Scala with my own single learningproject.
I combined views in swing for simple input and output and database access to mysql with some classes in scala. Target should be a small App that is well tested and show all aspects for later richer Apps. But having no Java-background its much input, looking over and decide for the perfect libraries, understanding the scala concepts and so on. So i make small steps in my little app.

The perfect way to make small steps in learning a new programming language is
doing some coding katas. Some solutions i found in the beginner section of codingkata.org

def fibonacci(n :Int) : Int = {
        n match {
            case 0 => 0
            case 1 => 1
            case _ => { ( fibonacci(n-1) + fibonacci(n-2)) }
        }
    }

So i will solve a few more katas, whenever i can not reach the next step or feature of my learning-app-project...

2/8/11

Syntax Highlighter installed.

Trying out this here for syntax highlightning...

// Test JavaScript looking good
function foo()
{
   if (counter <= 10)
      return;
} 

Editing Design | HTML must add brush for Scala:
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js' type='text/javascript'/>  

Simple Scala-Swing example:
package helloscala
import swing._

object SimpleTextView extends Frame {    
    title = "Simple Text View"
    location = new java.awt.Point( 200,100 )
    minimumSize = new java.awt.Dimension(600, 400)

    var outArea : TextArea =  new TextArea;
    showText("")

    def showText(sometext:String) = {
        outArea.font = new java.awt.Font("Arial", java.awt.Font.BOLD, 12)
        outArea.text = sometext
       
        contents = outArea
        open
    }
    def addText(moretext:String) = {
        outArea.text += moretext
    }
    def writeln(moretext:String) = addText(moretext+"\n")

} 

2/1/11

Start with Scala practice

Trying out the basics for a first blog:
  • my blog will contain code-snippets, how will they look better ?
    import javax.swing._

    object MainApplication extends SimpleSwingApplication {
      def top = new MainFrame {       title="MainApp" ...
  •  an image