Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
MapStruct dependency scope in a Maven project

MapStruct generates code at compile-time and it should not require any runtime dependencies:

How is MapStruct different from other bean mapping tools?

Unlike most other bean mapping tools, MapStruct doesn’t work at runtime but is a compile-time code generator.

Generating mapping code at build time has many advantages:

  • Excellent performance, as no reflection or byte code generation at runtime is needed; the generated code contains plain method invocations, just as if the mapper was hand-written
  • No runtime dependencies, making MapStruct a great solution for Android applications

Which dependency scope should be used in a Maven project? Should MapStruct be included as a provided dependency?

<dependencies>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
        <version>${org.mapstruct.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The org.mapstruct:mapstruct dependency contains the needed annotations to signal the org.mapstruct:mapstruct-processor what to do.

It also contains the Mappers factory that is used when using the default component model. Therefore, the scope of org.mapstruct:mapstruct depends on the component model that you are using:

Default component model

If you are using this component model then you need org.mapstruct:mapstruct during runtime if you are using Mappers or if you have dependencies between different mappers.

In theory you can use the default component model and instantiate your own mappers. However, dependencies between mappers are still going to use Mappers, unless you have instantiated your mapper in MyMapper.INSTANCE somehow already, then MapStruct will use MyMapper.INSTANCE to get the instance of the MyMapper. This would mean that you can still use the same scope as the other component models (see below for more information)

Other component model (spring, jsr330, cdi, etc.)

In this case you do not need org.mapstruct:mapstruct during runtime and you can use <optional>true</optional> with <scope>provided</scope>.

With Gradle this would be compileOnly dependency.

Note: Be careful when using Spring Boot and <scope>provided</scope> the Spring Boot maven plugin will still include the org.mapstruct:mapstruct dependency in the final provided jar. You'll need to ignore it by configuring the Spring Boot Maven plugin.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda