Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip generate-sources in Maven

Tags:

java

maven

build

Is there way to skip generate-sources in Maven?

Doing it via command line options

like image 527
kuhajeyan Avatar asked Mar 04 '14 12:03

kuhajeyan


People also ask

What does generate sources do in Maven?

The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.

What is Mvn clean install?

mvn clean install is the command to do just that. You are calling the mvn executable, which means you need Maven installed on your machine. (see How do you install Maven?) You are using the clean command, which will delete all previously compiled Java . class files and resources (like .

What is generated sources in Java?

It's a step in the build process that generates source files from other files, e.g. generating Java source files from XML schema files (JAXB). – Andreas. Nov 13, 2020 at 22:37. Generate Java Code from XSD, JSON, or for example MapStruct etc.

What does Mvn validate do?

validate - validate the project is correct and all necessary information is available. compile - compile the source code of the project. test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.


2 Answers

I've scenario where I generate CXF classes when ever I there is change in WSDL or WADL. Hence I generate it explicitly whenever I need. Hence I created a separate profile a new profile cxf-gen along with my usual dev, uat, syst. which has plugins to generate the classes. In short whenever I need to regenerate the classes I switch to the profile and run generate-sources. Here is sample profile I use.

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <envName>dev</envName>
        </properties>
    </profile>
    <profile>
        <id>uat</id>
        <properties>
            <envName>uat</envName>
        </properties>
    </profile>

    <profile>
        <id>jaxB-gen</id>
        <properties>
            <envName>dev</envName>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxb2-maven-plugin</artifactId>
                    <version>1.5</version>
                    <configuration>
                        <!-- CONFIGS ->
                    </configuration>
                    <executions>
                        <execution>
                            <id>xjc</id>
                            <goals>
                                <goal>xjc</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>code-gen</id>
        <properties>
            <envName>dev</envName>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-codegen-plugin</artifactId>
                    <version>${cxf.version}</version>
                    <executions>
                        <execution>
                            <id>generate-sources</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <!-- CONFIGS ->
                            </configuration>
                            <goals>
                                <goal>wsdl2java</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- wadl2java Required only when JAXRS classes are to be generated -->
                <plugin>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-wadl2java-plugin</artifactId>
                    <version>2.7.6</version>
                    <executions>
                        <execution>
                            <id>generate-sources</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <!-- CONFIGS ->
                            </configuration>
                            <goals>
                                <goal>wadl2java</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>com.googlecode.jsonschema2pojo</groupId>
                    <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                    <version>0.3.7</version>
                    <configuration>
                        <!-- CONFIGS ->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

            </plugins>
        </build>
    </profile>
</profiles>
like image 166
Karthik Prasad Avatar answered Sep 18 '22 17:09

Karthik Prasad


This command line option should work if you are using maven-source-plugin (works with Maven 3.6.0):
-Dmaven.source.skip=true

like image 25
boot-and-bonnet Avatar answered Sep 16 '22 17:09

boot-and-bonnet