How to ignore the Java Source directory during Maven Compilation?

前端 未结 5 2016
傲寒
傲寒 2020-12-13 19:59

I am trying to use the Lombok Maven Plugin to ensure the correct creation of Javadocs when using Lombok.

Lombok Maven introduces a new code generation goal, just pri

5条回答
  •  佛祖请我去吃肉
    2020-12-13 20:35

    The delombok goal is designed to transform java code from src/main/lombok to target/generated-source/delombok. Then, the other java code found in src/main/java is combined with target/generated-source/delombok to produce the combined java classes.

    It helps to think of delombok as a source code generator.

    So how can you get what you really want? (Note that Maven has an addCompileSourceRoot method, but not a corresponding removeCompileSourceRoot.) Imagine the following hack:

    1. Override the default from src/main/java to be ${project.build.directory}/generated-sources/delombok.
    2. Override the default delombok sourceDirectory from src/main/lombok to be src/main/java, and disable addOutputDirectory.

    Basically, you will use src/main/java, but Maven will ignore it and instead use target/generated-sources/delombok. The Lombok plugin will transform src/main/java into elaborated code in target/generated-sources/delombok.

    
      ${project.build.directory}/generated-sources/delombok
      
        
          org.projectlombok
          lombok-maven-plugin
          1.16.6.1
          
            
              delombok
              generate-sources
              
                delombok
              
              
                false
                src/main/java
              
            
          
        
      
    
    

    Note that you should not need to hack other plugins, like maven-jar-plugin or maven-javadoc-plugin, because they should respect the sourceDirectory.

    Use this hack at your own risk. (My guess is that this may confuse your IDE and some other developers.)

提交回复
热议问题