How to set up MapStruct with Apache Ant

487 views
Skip to first unread message

Aldo

unread,
Oct 17, 2016, 7:23:48 AM10/17/16
to mapstruct-users
Hello!

I am using Apache Ant as build tool. In the MapStruct reference guide Chapter 2 "Set up" it is stated, that MapStruct can be used with Ant. 

However, there is no further description or example in the reference guide and searching the web for this topic did not help me. I am wondering, how I can use MapStruct with Apache Ant, i.e. how I can trigger the annotation processing and mapper generation during the build process with Apache Ant.

Does anybody have experiences using MapStruct with Ant?

Thank you for any support!


Best regards,

Aldo

Gunnar Morling

unread,
Oct 17, 2016, 7:46:29 AM10/17/16
to Aldo, mapstruct-users
Hi,

This question and answer on stack overflow may be helpful to you: http://stackoverflow.com/questions/3644069/java-6-annotation-processing-configuration-with-ant

If you got it working, maybe you could send a pull request for the MapStruct documentation based on your findings (see https://github.com/mapstruct/mapstruct/tree/master/documentation/src/main/asciidoc)?

Cheers,

--Gunnar




--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aldo

unread,
Oct 17, 2016, 9:16:18 AM10/17/16
to mapstruct-users, flow...@gmail.com
Hi Gunnar

Thank you very much for your answer.

I tried the proposal from the 

 <target name="generate-mappers">
 
<mkdir dir="${generated.dir}/mapstruct/"/>
 
<javac srcdir="${src.dir}">
     
<compilerarg line="-processorpath ${base.lib.dir}/common"/>
     
<compilerarg line="-processor org.mapstruct.ap.MappingProcessor"/>
<!-- compilerarg line="-processor mapstruct-processor-1.1.0.CR1.jar"/ -->
     <compilerarg line="-s ${generated.dir}/mapstruct/"/>
 
</javac>
 
</target>

generate-mappers:
    [javac] Compiling 24 source files
    [javac] error: Annotation processor 'org.mapstruct.ap.MappingProcessor' not found
    [javac] 1 error

BUILD FAILED




Am Montag, 17. Oktober 2016 13:46:29 UTC+2 schrieb Gunnar Morling:
Hi,

This question and answer on stack overflow may be helpful to you: http://stackoverflow.com/questions/3644069/java-6-annotation-processing-configuration-with-ant

If you got it working, maybe you could send a pull request for the MapStruct documentation based on your findings (see https://github.com/mapstruct/mapstruct/tree/master/documentation/src/main/asciidoc)?

Cheers,

--Gunnar



2016-10-17 13:23 GMT+02:00 Aldo <flow...@gmail.com>:
Hello!

I am using Apache Ant as build tool. In the MapStruct reference guide Chapter 2 "Set up" it is stated, that MapStruct can be used with Ant. 

However, there is no further description or example in the reference guide and searching the web for this topic did not help me. I am wondering, how I can use MapStruct with Apache Ant, i.e. how I can trigger the annotation processing and mapper generation during the build process with Apache Ant.

Does anybody have experiences using MapStruct with Ant?

Thank you for any support!


Best regards,

Aldo

--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.

Aldo

unread,
Oct 17, 2016, 9:21:14 AM10/17/16
to mapstruct-users, flow...@gmail.com
Do you know what I should set the processor argument to? I tried with the qualified class name "org.mapstruct.ap.MappingProcessor" and also with the jar file name mapstruct-processor-1.1.0.CR1.jar. Both did not work, i.e. the annotation processor was not found.

P.s.: I am sorry, I accidentally posted the answer before I was finishing the editing.

Best regards,
Aldo

Aldo

unread,
Oct 19, 2016, 3:12:16 AM10/19/16
to mapstruct-users, flow...@gmail.com
Hi Gunnar

I finally succeeded by compiling first the sources without the mappers and then compiling the mappers and generating the mapper implementations. The processorpath argument did somehow not work, I just added the path to mapstruct jar-file to the classpath.

<target name="generate-mapstruct-mappers">
<!-- create dir for compiled classes and generated mappers -->
<mkdir dir="${basedir}/build/classes"/>
<mkdir dir="${basedir}/build/generated/mapstruct/"/>

<!-- compile classes without the mappers -->
<javac 
srcdir="${basedir}/src/main/java/"
destdir="${basedir}/build/classes/"
includeantruntime="false">
<classpath refid="classpath"/>
<exclude name="${basedir}/src/main/java/mappers/**"/>
</javac>

<!-- add mapstruct to the classpath -->
<path id="mapstruct.classpath">
   <path refid="classpath"/>
   <fileset dir="${lib}">
<include name="path/to/mapstruct/mapstruct.jar"/>
   </fileset>
</path>
<!-- compile the mappers and run mapstruct annotation processor -->
<javac 
srcdir="${basedir}/src/main/java/mappers"
destdir="${basedir}/build/classes/"
includeantruntime="false">
<classpath refid="mapstruct.classpath"/>
<compilerarg line="-processor org.mapstruct.ap.MappingProcessor"/>
<compilerarg line="-s ${basedir}/build/generated/mapstruct/"/>
</javac>
</target>


Thx and cheers,
Aldo


Am Montag, 17. Oktober 2016 13:46:29 UTC+2 schrieb Gunnar Morling:
Hi,

This question and answer on stack overflow may be helpful to you: http://stackoverflow.com/questions/3644069/java-6-annotation-processing-configuration-with-ant

If you got it working, maybe you could send a pull request for the MapStruct documentation based on your findings (see https://github.com/mapstruct/mapstruct/tree/master/documentation/src/main/asciidoc)?

Cheers,

--Gunnar



2016-10-17 13:23 GMT+02:00 Aldo <flow...@gmail.com>:
Hello!

I am using Apache Ant as build tool. In the MapStruct reference guide Chapter 2 "Set up" it is stated, that MapStruct can be used with Ant. 

However, there is no further description or example in the reference guide and searching the web for this topic did not help me. I am wondering, how I can use MapStruct with Apache Ant, i.e. how I can trigger the annotation processing and mapper generation during the build process with Apache Ant.

Does anybody have experiences using MapStruct with Ant?

Thank you for any support!


Best regards,

Aldo

--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.

Gunnar Morling

unread,
Nov 1, 2016, 6:17:36 PM11/1/16
to mapstruct-users, flow...@gmail.com
Hi Aldo,

I've created an example project for using MapStruct with Ant in our examples repo: https://github.com/mapstruct/mapstruct-examples/pull/11.

Note that the -processorpath option must point to the mapstruct-processor-xyz.jar, not the directory containing it. I reckon that was your original issue looking at your configuration again.

--Gunnar
Reply all
Reply to author
Forward
0 new messages