You can obtain a distribution bundle containing the MapStruct binaries, source code and API documentation from GitHub.
If you’re using Maven to build your project add the following to your pom.xml to use MapStruct:
... <properties> <org.mapstruct.version>1.6.3</org.mapstruct.version> </properties> ... <dependencies> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>${org.mapstruct.version}</version> </dependency> </dependencies> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <!-- depending on your project --> <target>1.8</target> <!-- depending on your project --> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> </path> <!-- other annotation processors --> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build>
When using a modern version of Gradle (>= 4.6), you add something along the following lines to your build.gradle:
dependencies { ... implementation 'org.mapstruct:mapstruct:1.6.3' annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.3' }
If using Gradle => 4.6 and < 5.2 you might want to look at gradle-apt-plugin. There might be some tweaks you want to apply to improve the handling of generated sources.
For older versions of Gradle (< 4.6), use something like this:
plugins { ... id 'net.ltgt.apt' version '0.21' } dependencies { ... compile 'org.mapstruct:mapstruct:1.6.3' apt 'org.mapstruct:mapstruct-processor:1.6.3' }
You can find a complete example in the mapstruct-examples project on GitHub.
Add the javac
task configured as follows to your build.xml file in order to enable MapStruct in your Ant-based project. Adjust the paths as required for your project layout.
... <javac srcdir="src/main/java" destdir="target/classes" classpath="path/to/mapstruct-1.6.3.jar"> <compilerarg line="-processorpath path/to/mapstruct-processor-1.6.3.jar"/> <compilerarg line="-s target/generated-sources"/> </javac> ...
You can find a complete example in the mapstruct-examples project on GitHub.