0

The problem is quite simple: there is an ant project that I should port to maven. As maven has a recommended/expected project directory structure, this would implicate much manual work if I restructure the directories of the java files. On the other hand, the project would also not be very happy with this solution, not mentioning others, using the packages of the current project.

Do you have any idea, how it would be possible to migrate to maven without having to change the directory structure? Thank you also in advance.

Tamas
  • 736
  • 2
  • 11
  • 27
  • This is one of the problems that could be simple labeled: we want new thing to be like the old thing - so why do you want the new thing. – Grzegorz Żur Nov 29 '13 at 15:38
  • 1
    Not sure about Maven, but Gradle lets you specify the directory structure if you don't want to use the conventional structure. – Lesleh Nov 29 '13 at 15:42
  • Grzegorz, The problem is that the project is an existing project but the new feature changes and the whole build management would be easier with Maven, even the management of external dependencies. Lesleh, thanks for the idea Gradle. – Tamas Nov 29 '13 at 15:47
  • 2
    Using maven in half-hearted way is not going to help. One core area of maven is dependency management. You could get that with IVY with ant or a tool like gradle(maturing fast). – Jayan Nov 29 '13 at 16:15
  • 2
    ANT and Maven are very different tools with different approaches that are near impossible to reconcile. Maven is all about standardizing your build so that plugins can make assumptions about how the code is setup... I've been searching for years and have yet to see a successful "common build approach" in ANT. Every build engineer has his own opinion which is great but and an enemy to standards. Best thing you can do is restructure your ANT build to take advantage of Maven dependency management. Take a peak at this code which might help in a transition. https://github.com/myspotontheweb/ant2ivy – Mark O'Connor Nov 29 '13 at 18:57

2 Answers2

2

It is strongly recommended that you use Maven's standard directory structure, but you can set a custom src directory in your pom. Something like:

<build>
 <sourceDirectory>path\to\actual\src</sourceDirectory>
</build>

The following might be what you're looking for: Handling unconventional source directory for a web project in maven

Edit: The following is a list of default settings that are set in the Maven Super POM and can be overriden in your project's pom.xml

<build>
    <directory>target</directory>
    <outputDirectory>target/classes</outputDirectory>
    <finalName>${artifactId}-${version}</finalName>
    <testOutputDirectory>target/test-classes</testOutputDirectory>
    <sourceDirectory>src/main/java</sourceDirectory>
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
      </testResource>
    </testResources>
</build>
Community
  • 1
  • 1
jmcmahon
  • 630
  • 1
  • 7
  • 14
1

I would strongly recommend you commit to the restructure. You are only adding to your problems if you do not.

However, if you really must maintain your original structure you could make use of soft folders of some sort. On Windows you can use SymLinks - I expect there are other alternatives for other OS's.

Make a new folder beside your sources folder (I called mine Maven). In that folder, build a structure that mirrors the required Maven structure but only place pom files in it. Make symlinks to the old location.

It is possible to automate this but it takes some work.

I would only recommend this solution while you are in a transition phase while some developers are still building with ant or you are transitioning your code to the new structure in your SCC system.

OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
  • Thanks for the quick response. The problem I can see in this solution is that the change in the directory structure would implicate code changes in the java source files, because the package designation should be adjusted. This would be necessary if the package names do not reflect the directory structure at the time of the compilation. Or I have misunderstood your comment. – Tamas Nov 29 '13 at 16:05
  • 1
    @Tamas - I think you have misunderstood the Maven structure - your old `com` folder still exists in Maven but as `src/main/java/com`. All your packages remain the same. There is some strangeness with web apps but libraries and POJOs are fine. – OldCurmudgeon Nov 29 '13 at 16:27