davidmoten / odata-client

Java client generator for a service described by OData CSDL 4.0 metadata. Includes Microsoft Graph clients (v1.0 and Beta), Graph Explorer client, Analytics for DevOps, Dynamics CRM clients
Apache License 2.0
36 stars 8 forks source link

Unable to generate sources using odata-client-maven-plugin #484

Closed NCarrellOmni closed 1 month ago

NCarrellOmni commented 2 months ago

On attempting to generate sources using the odata-client-maven-plugin v 0.2.1, I always get the error "The parameters 'metadata' for goal com.github.davidmoten:odata-client-maven-plugin:0.2.1:generate are missing or invalid". I am using mvn odata-client:generate when attempting to generate sources.

I have some generated code in the 'target' directory which was successfully generated several months ago. Removing this generated code hasn't helped.

The project structure: image

I downloaded the XML file provided in odata-client-microsoft-dynamics, microsoft-dynamics-crm4-v9.1-metadata.xml. I am still getting the same error. I changed the "namespace" property from Microsoft.Dynamics.CRM to mscrm and this has not helped.
I have tried doing the same on another computer with a new project with the same results.

Are we using this incorrectly? I have only been able to get sources to generate two times successfully, both were multiple months ago.

This is the pom.xml that we are using. The CRM metadata file has been renamed to "mscrm.xml" but the name doesn't seem to matter in this case.

<?xml version="1.0" encoding="UTF-8"?>
<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>com.tenant-name</groupId>
    <artifactId>omni-odata</artifactId>
    <version>0.0.3</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.github.davidmoten</groupId>
            <artifactId>odata-client-microsoft-client-builder</artifactId>
            <version>0.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.14</version>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20240303</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.davidmoten</groupId>
                <artifactId>odata-client-maven-plugin</artifactId>
                <version>0.2.1</version>
                <executions>
                    <execution>
                        <id>generate-v1-client</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <metadata>src/main/odata/mscrm.xml</metadata>
                            <schemas>
                                <schema>
                                    <namespace>mscrm</namespace>
                                    <packageName>com.repo-id.crm9</packageName>
                                    <failOnMissingEntitySet>false</failOnMissingEntitySet>
                                </schema>
                            </schemas>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
davidmoten commented 2 months ago

This is part of the unit testing of the project. Do as per https://github.com/davidmoten/odata-client/blob/master/odata-client-microsoft-dynamics/pom.xml. You seem to be using the alias for the namespace instead of the Namespace value. Just use the raw Namespace value: <namespace>Microsoft.Dynamics.CRM</namespace>. The namespace value is obtained from this metadata line:

  <edmx:DataServices>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Microsoft.Dynamics.CRM" Alias="mscrm">
davidmoten commented 2 months ago

Ok, to demonstrate that generation works fine I copied the directory odata-client-microsoft-dynamics somewhere else and updated the pom so it looks like below. Built fine. You could use the below pom as guide.

<?xml version="1.0" encoding="UTF-8"?>
<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>davemoten</groupId>
    <artifactId>odata-client-microsoft-dynamics</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <description>Java client as template for Microsoft Dynamics organisation endpoints</description>
    <properties>
        <odata.client.version>0.2.3-SNAPSHOT</odata.client.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>com.github.davidmoten</groupId>
            <artifactId>odata-client-microsoft-client-builder</artifactId>
            <version>${odata.client.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.14</version>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.23.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.davidmoten</groupId>
            <artifactId>junit-extras</artifactId>
            <version>0.4</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.davidmoten</groupId>
                <artifactId>odata-client-maven-plugin</artifactId>
                <version>${odata.client.version}</version>
                <executions>
                    <execution>
                        <id>generate-v1-client</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <metadata>src/main/odata/microsoft-dynamics-crm4-v9.1-metadata.xml</metadata>
                            <schemas>
                                <schema>
                                    <namespace>Microsoft.Dynamics.CRM</namespace>
                                    <packageName>microsoft.dynamics.crm</packageName>
                                    <failOnMissingEntitySet>false</failOnMissingEntitySet>
                                </schema>
                            </schemas>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
davidmoten commented 2 months ago

BTW if I run mvn odata-client:generate I get the same error as you. Just run mvn install or to be more specific run mvn generate-sources.

What you are missing is the execution id. It works for me if I run mvn odata-client:generate@generate-v1-client.