Search code examples
javaeclipsemavendependency-managementmaven-eclipse-plugin

Very lightweight Eclipse-Maven integration - dependency management only?


From my experience, Maven is often an overkill in small/experimental applications. But depencency management is very useful feature of Maven and actually the only one that can be really helpful in mentioned type of applications.

I wonder if I can have a very minimal and lightweight Eclipse-Maven integration that provides only adding Maven dependencies to Eclipse project classpath in the simpliest possible way.

Especially I don't want to:

  • apply to any Maven conventions (including project layout conventons)
  • install and use any specific Eclipse plugins (Eclipse shouldn't know at all that it is "Maven project" and treat it in any special way)
  • depend on/be bound to Maven in any other way than using it as lightweight jars/libraries downloader

My first (and only) idea is to use Eclipse Maven plugin from command line to manage project classpath. But by default this plugin does more than it (sets up default maven project layout, manage builders). Can I limit this plugin to only do what I want?

Or can I reach the goals I described in any other way?


Solution

  • I found a solution that fits very well to needs/use case that I described in question:

    1. I created very minimal pom file in Eclipse project root:

    <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.sobczyk.piotr</groupId>
        <artifactId>mvn-eclipse-test</artifactId>
        <version>1.0.0</version>
    
        <build>
            <sourceDirectory>src</sourceDirectory>
            <outputDirectory>bin</outputDirectory>
        </build>
    
        <dependencies>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.16</version>
            </dependency>
        </dependencies>
    </project>
    

    This .pom file consists of three parts:

    • Required Maven stuff, ie. modelVersion and GAV
    • build section where Maven default source and output directories and overriden to mimic Eclipse environment (it's the answer to the part of question on limiting maven-eclipse-plugin behaviour, some other eclipse:eclipse goal options like buildcommands may be useful in some more complex cases)
    • dependencies section listing dependencies that I need to have on project classpath

    2. From command line I invoked following commands:

    mvn eclipse:configure-workspace -Declipse.workspace=C:/myworkspace
    cd C:/myworkspace/myproject
    mvn eclipse:eclipse
    

    3. Each time I want to update Eclipse project classpath from Maven file I can do one of two things:

    • invoke last two lines from command line
    • bind mvn eclipse:eclipse to Eclipse external tool configuration and invoke it with single click