Search code examples
javagradlemapstructcode-generationobject-object-mapping

Using MapStruct SPI custom AccessorNamingStrategy with Gradle


I am trying to implement a custom accessor naming strategy like documented here:

http://mapstruct.org/documentation/stable/reference/html/#using-spi

However, I can't get it to work with Gradle. There only seems to be a usage example for Maven:

https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-spi-accessor-naming

Has anyone even tried using this feature with Gradle?

I tried following the Maven project structure and adapt the pom.xml to build.gradle like this:

plugins {
    id 'net.ltgt.apt' version "0.8"
}

dependencies {
  // Add project containing custom DefaultAccessorNamingStrategy implementation 
  // and corresponding declaration in META-INF/services to annotation processor classpath 
  apt project(':my-project-containg-naming-strategy-impl') 
  // Add MapStruct annotation processor to annotation processor classpath
  apt "org.mapstruct:mapstruct-processor:1.2.0.Final"

  compile "org.mapstruct:mapstruct-jdk8:1.2.0.Final"
}

However, my custom AccessorNamingStrategy doesn't have any effect. Unfortunately I have absolutely no idea how to even get debugging information on this ...


Solution

  • Actually it does work just as described above. It seems that I just had a typo somewhere in my Gradle files ...