apollo-client-maven-plugin icon indicating copy to clipboard operation
apollo-client-maven-plugin copied to clipboard

Generate sources error Service.getEnabled is null

Open expe-elenigen opened this issue 11 months ago • 4 comments

hi, I copied the configuration from the example apollo-client-maven-plugin-tests with:

        <groupId>com.github.aoudiamoncef</groupId>
        <artifactId>apollo-client-maven-plugin</artifactId>
        <version>${apollo-client-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <services>
                <abc-api>
                  <enabled>true</enabled>
        ...

With almost no differences, but when I execute: mvn generate-sources with Java 17 and Kotlint 1.9.23 and I get this strange error:

[ERROR] Failed to execute goal com.github.aoudiamoncef:apollo-client-maven-plugin:7.0.0:generate (default) on project abc-client: Execution default of goal com.github.aoudiamoncef:apollo-client-maven-plugin:7.0.0:generate failed: Cannot invoke "com.github.aoudiamoncef.apollo.plugin.config.Service.getEnabled$apollo_client_maven_plugin()" because the return value of "java.util.Map$Entry.getValue()" is null -> [Help 1]

My configuration has the enabled flag set to true, so I don't understand why it's complaining about being null.

expe-elenigen avatar Mar 19 '24 16:03 expe-elenigen

I tried all the older versions down to 5.0.0 and I also tried to upgrade to Java 21 and it's always the same issue. As reference, I'm using Maven 3.9.3.

expe-elenigen avatar Mar 27 '24 20:03 expe-elenigen

After trying a lot of configurations, I finally found the root cause, I was using the tag:

<generateModelBuilder>true</generateModelBuilder>

which means the tag was missing a s at the end, so after I fixed it the build passed:

<generateModelBuilders>true</generateModelBuilders>

Just to give more context, originally we were using the plugin:

<groupId>com.github.sparow199</groupId>
<artifactId>apollo-client-maven-plugin</artifactId>

... and as you can guess, in that plugin we used the same tag, but without the s at the end, so when I migrated I compared the spec with this new plugin and I didn't noticed the small difference and I simply copied the tag over.

This means, whenever a tag is not recognized, it would generate this error which leave us no clue to understand what's the root cause of the problem. Would it be possible to improve the message?

expe-elenigen avatar Mar 27 '24 23:03 expe-elenigen

It's painful to debug when the error comes from the configuration of the maven properties.

aoudiamoncef avatar Mar 28 '24 00:03 aoudiamoncef

What do you mean by "comes from the configuration of the maven properties? This configuration is in this heriarchy:

<build>
  <plugins>
      <plugin>
        <groupId>com.github.aoudiamoncef</groupId>
        <artifactId>apollo-client-maven-plugin</artifactId>
        <version>${apollo-client-maven-plugin.version}</version>
        <executions>
          <execution>
            <configuration>
              <services>
                <book-api>
                   <compilationUnit>
                     <compilerParams>
                       <generateModelBuilders>true</generateModelBuilders>

I also noticed, even if the tag is correct, if the value is not, it would generate the same error message, for example, I defined:

<nullableFieldStyle>jsr305Annotations</nullableFieldStyle>

Since I just looked quickly in the code and found:

     * - `jsr305Annotations`: Fields will be generated with JSR 305's `javax.annotation.Nullable` annotation if nullable, or
     * `javax.annotation.Nonnull` if not.

It's only after I realized, I should put JSR_305_ANNOTATIONS.

expe-elenigen avatar Mar 28 '24 00:03 expe-elenigen