Mapstruct unmappedTargetPolicy WARN 好像没有效果
Mapstruct unmappedTargetPolicy WARN seems to have no effect
我正在使用 Mapstruct 1.3.0 投影此源对象;
import lombok.Data;
@Data
public class SimpleSource {
private String firstField;
private String secondField;
private String noMappingDefined;
}
进入这个 DTO:
import lombok.Data;
@Data
public class SimpleDestination {
private String field1;
private String field2;
}
在我的界面中,我没有为字段定义任何映射 "noMappingDefined"
@Mapper
public interface TestMapper {
@Mapping(source = "firstField", target = "field1")
@Mapping(source = "secondField", target = "field2")
SimpleDestination sourceToDestination(SimpleSource source);
@InheritInverseConfiguration
SimpleSource destinationToSource(SimpleDestination destination);
}
在 POM 的 compilerArgs 中将 unmappedTargetPolicy 设置为 WARN 不会在我构建项目时产生任何通知,并且在 Mapstruct 生成的目标 class 中看不到没有映射的字段。
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Beta2</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
<compilerArg>
-Amapstruct.unmappedTargetPolicy=WARN
</compilerArg>
</compilerArgs>
</configuration>
生成的 class 没有像预期的那样包含未映射的字段,但我希望在构建项目时看到警告。
如果我将 unmappedTargetPolicy 更改为 ERROR,则构建失败。
无论是在 POM 中配置还是在界面上的 @Mapper 注释中配置,行为都是一样的。
还有其他人 运行 关注这个问题吗?我正在处理一个项目,该项目有数百个要映射的字段,并非所有字段都至关重要,但很高兴知道我是否遗漏了任何字段。
谢谢。
原来是 POM 问题,我添加了 showWarnings 标签并将其设置为 true;
<showWarnings>
true
</showWarnings>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
<compilerArg>
-Amapstruct.unmappedTargetPolicy=WARN
</compilerArg>
</compilerArgs>
现在我看到了构建项目时预期的警告。
我正在使用 Mapstruct 1.3.0 投影此源对象;
import lombok.Data;
@Data
public class SimpleSource {
private String firstField;
private String secondField;
private String noMappingDefined;
}
进入这个 DTO:
import lombok.Data;
@Data
public class SimpleDestination {
private String field1;
private String field2;
}
在我的界面中,我没有为字段定义任何映射 "noMappingDefined"
@Mapper
public interface TestMapper {
@Mapping(source = "firstField", target = "field1")
@Mapping(source = "secondField", target = "field2")
SimpleDestination sourceToDestination(SimpleSource source);
@InheritInverseConfiguration
SimpleSource destinationToSource(SimpleDestination destination);
}
在 POM 的 compilerArgs 中将 unmappedTargetPolicy 设置为 WARN 不会在我构建项目时产生任何通知,并且在 Mapstruct 生成的目标 class 中看不到没有映射的字段。
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Beta2</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
<compilerArg>
-Amapstruct.unmappedTargetPolicy=WARN
</compilerArg>
</compilerArgs>
</configuration>
生成的 class 没有像预期的那样包含未映射的字段,但我希望在构建项目时看到警告。
如果我将 unmappedTargetPolicy 更改为 ERROR,则构建失败。
无论是在 POM 中配置还是在界面上的 @Mapper 注释中配置,行为都是一样的。
还有其他人 运行 关注这个问题吗?我正在处理一个项目,该项目有数百个要映射的字段,并非所有字段都至关重要,但很高兴知道我是否遗漏了任何字段。
谢谢。
原来是 POM 问题,我添加了 showWarnings 标签并将其设置为 true;
<showWarnings>
true
</showWarnings>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
<compilerArg>
-Amapstruct.unmappedTargetPolicy=WARN
</compilerArg>
</compilerArgs>
现在我看到了构建项目时预期的警告。