ANT to Maven Migration. Maven alternative to build.xml

2.3k views Asked by At

Background:

I am working on a open source tool called draw.io which is based on ANT build system and uses Java servelets to handle request. I am supposed to migrate it to spring boot with using same front end files. I put those files in static folder and tried to build the project. I figured that the front end js files were not getting build (i.e. were not getting converted to app.min.js, which is the main entry point for front end files), in the process and none of the js changes were getting reflected in the file.

I figured that this process was mentioned in build.xml as part of various steps which is ANT specific configuration. Now, I have to achieve the same in maven as the migration process.

How do we convert build.xml to maven or what is the maven alternative of achieving the tasks mentioned in the build.xml as part of build process?

This is the high level view of build.xml:->

enter image description here

I am also providing the link of build.xml here...

Please provide me with some direction.

2

There are 2 answers

2
J Fabian Meier On

For Maven, you need a pom.xml. There you need to define and configure the plugins you need. If you have a specific procedure written in Ant that you want to reuse, you can call it with the Maven Antrun Plugin.

Generally, Maven is very different from Ant. You don't write procedural code, but configure plugins running in a lifecycle.

2
Praveen On

Before migrating to maven, I hope you understand why you are moving to maven from ant.

You should try for finding alternative plugins for the relevant ant task. The below plugin might do what you are trying to achieve in ant

<plugin>
      <groupId>com.github.blutorange</groupId>
      <artifactId>closure-compiler-maven-plugin</artifactId>
      <version>2.16.0</version>
      <configuration>
        <!-- Base configuration for all executions (bundles) -->
        <baseSourceDir>${project.basedir}/src/main/resources</baseSourceDir>
        <baseTargetDir>${project.build.directory}/generated-resources</baseTargetDir>
      </configuration>
      <executions>
        <!-- Process all files in the "includes" directory individually-->
        <execution>
          <id>default-minify</id>
          <configuration>
            <encoding>UTF-8</encoding>
            <sourceDir>includes</sourceDir>
            <targetDir>includes</targetDir>
            <includes>**/*.js</includes>
            <skipMerge>true</skipMerge>
            <closureLanguageOut>ECMASCRIPT5</closureLanguageOut>
          </configuration>
          <goals>
            <goal>minify</goal>
          </goals>
          <phase>generate-resources</phase>
        </execution>
      </executions>
    </plugin>

More details about the plugin : closure-compiler-maven-plugin

There are few cases during my ant to maven migration, I came across some custom tasks which I was not able to find appropriate plugins.

I used maven-antrun-plugin which keeps existing ant tasks in maven.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        ...
    </executions>
</plugin>

More details about how to use the maven antrun plugin : See this tutorial