tomasbjerre / git-changelog-maven-plugin

Maven plugin that can generate a changelog, or releasenotes, from git repository
Other
80 stars 36 forks source link

Error when trying to add any javascriptHelper #57

Closed arkadioz closed 10 months ago

arkadioz commented 10 months ago

I am trying to add a custom helper but even if I copy paste the config provided as example here https://github.com/tomasbjerre/git-changelog-maven-plugin?tab=readme-ov-file#example---custom-helpers I get the following error:

[INFO] --- git-changelog-maven-plugin:1.101.0:git-changelog (GenerateGitChangelog) @ demo ---
[INFO] Extended variables:
[ERROR] GitChangelog
java.lang.NullPointerException
    at com.github.jknack.handlebars.helper.DefaultHelperRegistry.engine (DefaultHelperRegistry.java:304)
    at com.github.jknack.handlebars.helper.DefaultHelperRegistry.registerHelpers (DefaultHelperRegistry.java:193)
    at com.github.jknack.handlebars.Handlebars.registerHelpers (Handlebars.java:859)
    at se.bjurr.gitchangelog.api.GitChangelogApi.withHandlebarsHelper (GitChangelogApi.java:273)
    at se.bjurr.gitchangelog.plugin.GitChangelogMojo.execute (GitChangelogMojo.java:224)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)

Not sure if im missing something that is ment to be obvious like maybe a dependency, but hopefully @tomasbjerre or someone can point me out in the right direction, here is my plugin config and also the javascript helper I was trying to add just for starting to learn:

            <plugin>
                <groupId>se.bjurr.gitchangelog</groupId>
                <artifactId>git-changelog-maven-plugin</artifactId>
                <version>1.101.0</version>
                <executions>
                    <execution>
                        <id>GenerateGitChangelog</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>git-changelog</goal>
                        </goals>
                        <configuration>
                            <javascriptHelper>
                                <![CDATA[
Handlebars.registerHelper('helloFunction', function() {
 return "hello";
 });
                                ]]>
                            </javascriptHelper>
                            <templateContent>
                                <![CDATA[
## Changelog {{helloFunction}}

{{#commits}}
## {{messageTitle}}
{{/commits}}
]]>
                            </templateContent>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
arkadioz commented 10 months ago

@tomasbjerre do you know if there is something I can do by my side to fix it? I saw your commit in their library about the engine being null, but im not sure if I have to add something in my code to make that engine not null? thanks for all your help

tomasbjerre commented 10 months ago

Perhaps if you add Nashorn as a dependency.

<build>
  <plugins>
   <plugin>
    <groupId>se.bjurr.gitchangelog</groupId>
    <artifactId>git-changelog-maven-plugin</artifactId>
    <version>${changelog}</version>
    <dependencies>
     <dependency>
       <groupId>org.openjdk.nashorn</groupId>
       <artifactId>nashorn-core</artifactId>
       <version>15.4</version>
     </dependency>
    </dependencies>
   </plugin>
  </plugins>
</build>
arkadioz commented 10 months ago

That dependency solved it, thanks, why did you not add it on the example I mentioned at the start of this issue? I think it should be there in the example if it is needed, is my suggestion :), thanks again