filiphr/mapstruct-builder-accessor


Alternative Accessor Naming Strategy for MapStruct that supports builder setters

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    
	dependencies {
		implementation 'com.github.filiphr:mapstruct-builder-accessor:1.0.0'
	}
	dependencies {
		implementation("com.github.filiphr:mapstruct-builder-accessor:1.0.0")
	}
	<dependency>
	    <groupId>com.github.filiphr</groupId>
	    <artifactId>mapstruct-builder-accessor</artifactId>
	    <version>1.0.0</version>
	</dependency>

                            
    libraryDependencies += "com.github.filiphr" % "mapstruct-builder-accessor" % "1.0.0"
        
        

                            
    :dependencies [[com.github.filiphr/mapstruct-builder-accessor "1.0.0"]]
        
        

Readme


MapStruct builder accessor

This project supports an alternative AccessorNamingStrategy which supports different builder styles.

IMPORTANT: This is not a support for using builders for mappings, but just the discovery of the properties within a builder type.

IMPORANT2: This is not yet published on maven central. If you want to use it as a dependency you can use jitpack.io

Using

In order to use this accessor strategy one just needs to add the following dependencies:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <annotationProcessorPaths>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${mapstruct.version}</version>
            </path>
            <path>
                <groupId>com.github.filiphr</groupId>
                <artifactId>mapstruct-builder-accessor</artifactId>
                <version>${mapstruct-builder-accessor.version}</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

In order this to work nicely with IntelliJ (due to IDEA-150621) one needs to add the the mapstruct processor and the builder accessor to their main pom dependencies

<dependencies>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>${mapstruct.version}</version>
        <!-- IntelliJ does not pick up the processor if it is not in the dependencies.
         There is already an open issue for IntelliJ see https://youtrack.jetbrains.com/issue/IDEA-150621
        -->
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.github.filiphr</groupId>
        <artifactId>mapstruct-builder-accessor</artifactId>
        <version>${project.version}</version>
        <!-- IntelliJ does not pick up the processor if it is not in the dependencies.
         There is already an open issue for IntelliJ see https://youtrack.jetbrains.com/issue/IDEA-150621
        -->
        <scope>provided</scope>
    </dependency>
</dependencies>

Building from source

In order to build this project to source you need to run ./mvnw clean install