Question

I have a problem and could not identify the reason until now.

I have a maven project that has several modules. One of these modules is the webservices client.

So, during development, when running the install in maven, it needs to access the local server to generate the client. When I run the plugin to generate the release of the project, clients should point to the production server.

To do this I set as a key property ${server.address} which is used to point to the server when generating the clients. There is one profile which, when active, this key property rewrites the address to the production server.

What's going on? Running mvn install is generating correctly, ie, pointing to the local server. When I generate the release using the command mvn release:prepare -B release:perform -Denv=prd is not rewriting the variable as it should.

The strange thing is that if I run mvn install -Denv=prd, it generates correctly, pointing to the production server.

Could someone give me a hint of what to change to work also in release cycle?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>artifactId</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <server.address>http://localhost:8080</server.address>
    </properties>

    <profiles>
        <profile>
            <id>prd</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>prd</value>
                </property>
            </activation>
            <properties>
                <server.address>http://srvprd009:8080</server.address>
            </properties>
          </profile>
    </profiles>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-client</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>src/main/gen</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${server.address}/services/utilities?wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>${project.package}</extraarg>
                                        <extraarg>-impl</extraarg>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-frontend</extraarg>
                                        <extraarg>jaxws21</extraarg>
                                        <extraarg>-xjc-XhashCode</extraarg>
                                        <extraarg>-xjc-Xequals</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-frontend-jaxws</artifactId>
                        <version>${cxf.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-transports-http</artifactId>
                        <version>${cxf.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.4</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>${maven-clean-plugin.version}</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>src/main/gen</directory>
                            <includes>
                                <include>**/*.*</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>${build-helper-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/gen</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ts-core</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>corporate-tools.fragmental.security</groupId>
            <artifactId>basic-ws-client</artifactId>
            <version>${fragmental.version}</version>
        </dependency>

        <!-- JEE -->
        <dependency>
            <groupId>javax.j2ee</groupId>
            <artifactId>j2ee</artifactId>
            <version>1.4</version>
            <scope>provided</scope>
        </dependency>

        <!-- JAX-WS -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>${jaxws.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>${jaxws.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.xml.soap</groupId>
                    <artifactId>saaj-api</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>jsr250-api</artifactId>
                    <groupId>javax.annotation</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>
Was it helpful?

Solution 3

I fixed my problem creating two profiles, assuming that first has de dafault activation = true and set my server.address to localhost.

The second profile that set server.address to prd server is called by command line directly by -P prd

So, when I execute with no arguments, the default profile sets the server.address to localhost:8080 and when I execute the release, I use -P prd and the release works fine.

thank you for your answers.

OTHER TIPS

The release plugin has a kinda strange (for me ;)) usage with special properties and forwarding them to the real goal executed. If you use normal profile argument -Pprod this would work. However most other arguments you add at mvn call are ignored. So could you try the following one:

mvn release:prepare -B release:perform -Darguments="-Denv=prd" 

I believe you are using Maven 2.0.x right?

If I remember correctly, property overriding in profile is not working fine at or before Maven 2.0.7. Upgrade to latest 2.0.x (2.0.11) or even 2.2.x/3.0.x will work as you expected.

However, a bit off topic, I believe you are accessing the server to get the WSDL right? I don't think it is a good idea especially for release build, because it is making the build non-reproducible. Consider putting the WSDL with the source code (at least for release build) to make build reproducible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top