You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Matthew Compton <co...@gmail.com> on 2020/08/27 19:40:56 UTC

Issue using common Velocity template with version 3.2.0 of Maven Archetype Plugin

Hello all,

The recently released version 3.2.0 of the Maven Archetype Plugin has broken an archetype I created. I have confirmed my archetype still works with version 3.1.2 of the plugin but my team and I normally run "mvn archetype:generate …” just so we don’t have to specify a particular version of the plugin, but now Maven will pick up the 3.2.0 version of the plugin and fail. I am aware that using "mvn org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate …” will work around the problem, but I’d still like to fix my archetype to work with the latest version of the plugin.

The problem appears to be that something has changed with how the class path/resources are setup with the velocity template engine when rendering templates. I tried looking through the release notes but it just looks like version numbers were bumped, so I doesn’t seem like this was an intentional change in behavior.

The source of the problem is my archetype has a common 'META-INF/common-variable-definitions.vm’ that contains variables that are used in multiple files within the archetype. This worked great with earlier versions of the archetype plugin, each template that needed the common variable definitions simply needed  a #parse( "META-INF/common-variable-definitions.vm” ) at the top of the file and then all of the usual replacements that were needed are available. Now, with the 3.2.0 version of the plugin I get the following error:


[ERROR] ResourceManager : unable to find resource 'archetype-resources/META-INF/common-variable-definitions.vm' in any resource loader.
[ERROR] #parse(): cannot find template 'archetype-resources/META-INF/common-variable-definitions.vm', called at archetype-resources/pom.xml[line 1, column 1]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.327 s
[INFO] Finished at: 2020-08-26T16:28:24-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.0:integration-test (default-integration-test) on project demo-archetype: 
[ERROR] Archetype IT 'basic' failed: Error merging velocity templates: Unable to find resource 'archetype-resources/META-INF/common-variable-definitions.vm'
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


The issue is that the Velocity engine now expects the common definitions file in 'archetype-resources/META-INF' instead of a top-level 'META-INF' directory. I tried moving the file to 'archetype-resources/META-INF/common-variable-definitions.vm', but I found that only worked for the “first level”, and it essentially expected that file to copied into every level of the directory hierarchy of the archetype resources that had templates to render, which makes trying to do this totally pointless, I might as well copy the definitions into the top of each file like I had done in a very early version of my archetype. I also tried using “../“ relative paths (like #parse( “../META-INF/common-variable-definitions.vm” )) in files deeper into the directory hierarchy to reference back up to a single common velocity template, but could not get that to work either.

Is there something I can do to get this working again with version 3.2.0? Or is this no something that is actually supported and I was just getting lucky before?

To help reproduce the problem I created a simple example project to demonstrate this change in behavior between the two versions of the Maven Archetype Plugin. The top-level pom.xml in the attach tar has the following properties which you can comment/uncomment to switch between a working and failing version.

 <properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   <!-- This version of archetype plugin works -->
   <!--<maven-archetype-plugin.verson>3.1.2</maven-archetype-plugin.verson>-->
   <!-- This version of archetype plugin does not work -->
   <maven-archetype-plugin.verson>3.2.0</maven-archetype-plugin.verson>
 </properties>

If you uncompress the attached tar and call ‘mvn clean verify’ you can see how it works with 3.1.2 and fails with 3.2.0.

Thank you for the help,

Matt


Re: Issue using common Velocity template with version 3.2.0 of Maven Archetype Plugin

Posted by Matthew Compton <co...@gmail.com>.
Thanks for the reply Martin, I’ve created https://issues.apache.org/jira/browse/ARCHETYPE-609 as requested.

Matt

> On Aug 29, 2020, at 7:23 AM, Martin Kanters <ma...@apache.org> wrote:
> 
> Hi Matt,
> 
> Thanks a lot for your extensive bug report including sample project. Could
> you please create a bug in Jira? [1]
> It will make it easier to pick up the issue and assign the potential fix to
> a future release.
> 
> Regards, Martin
> 
> [1] https://issues.apache.org/jira/projects/ARCHETYPE/issues/
> 
> Op do 27 aug. 2020 om 21:41 schreef Matthew Compton <co...@gmail.com>:
> 
>> Hello all,
>> 
>> The recently released version 3.2.0 of the Maven Archetype Plugin has
>> broken an archetype I created. I have confirmed my archetype still works
>> with version 3.1.2 of the plugin but my team and I normally run "mvn
>> archetype:generate …” just so we don’t have to specify a particular version
>> of the plugin, but now Maven will pick up the 3.2.0 version of the plugin
>> and fail. I am aware that using "mvn
>> org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate …” will work
>> around the problem, but I’d still like to fix my archetype to work with the
>> latest version of the plugin.
>> 
>> The problem appears to be that something has changed with how the class
>> path/resources are setup with the velocity template engine when rendering
>> templates. I tried looking through the release notes but it just looks like
>> version numbers were bumped, so I doesn’t seem like this was an intentional
>> change in behavior.
>> 
>> The source of the problem is my archetype has a common
>> 'META-INF/common-variable-definitions.vm’ that contains variables that are
>> used in multiple files within the archetype. This worked great with earlier
>> versions of the archetype plugin, each template that needed the common
>> variable definitions simply needed  a #parse(
>> "META-INF/common-variable-definitions.vm” ) at the top of the file and then
>> all of the usual replacements that were needed are available. Now, with the
>> 3.2.0 version of the plugin I get the following error:
>> 
>> 
>> [ERROR] ResourceManager : unable to find resource
>> 'archetype-resources/META-INF/common-variable-definitions.vm' in any
>> resource loader.
>> [ERROR] #parse(): cannot find template
>> 'archetype-resources/META-INF/common-variable-definitions.vm', called at
>> archetype-resources/pom.xml[line 1, column 1]
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] BUILD FAILURE
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] Total time:  1.327 s
>> [INFO] Finished at: 2020-08-26T16:28:24-07:00
>> [INFO]
>> ------------------------------------------------------------------------
>> [ERROR] Failed to execute goal
>> org.apache.maven.plugins:maven-archetype-plugin:3.2.0:integration-test
>> (default-integration-test) on project demo-archetype:
>> [ERROR] Archetype IT 'basic' failed: Error merging velocity templates:
>> Unable to find resource
>> 'archetype-resources/META-INF/common-variable-definitions.vm'
>> [ERROR] -> [Help 1]
>> [ERROR]
>> [ERROR] To see the full stack trace of the errors, re-run Maven with the
>> -e switch.
>> [ERROR] Re-run Maven using the -X switch to enable full debug logging.
>> [ERROR]
>> [ERROR] For more information about the errors and possible solutions,
>> please read the following articles:
>> [ERROR] [Help 1]
>> http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
>> 
>> 
>> The issue is that the Velocity engine now expects the common definitions
>> file in 'archetype-resources/META-INF' instead of a top-level 'META-INF'
>> directory. I tried moving the file to
>> 'archetype-resources/META-INF/common-variable-definitions.vm', but I found
>> that only worked for the “first level”, and it essentially expected that
>> file to copied into every level of the directory hierarchy of the archetype
>> resources that had templates to render, which makes trying to do this
>> totally pointless, I might as well copy the definitions into the top of
>> each file like I had done in a very early version of my archetype. I also
>> tried using “../“ relative paths (like #parse(
>> “../META-INF/common-variable-definitions.vm” )) in files deeper into the
>> directory hierarchy to reference back up to a single common velocity
>> template, but could not get that to work either.
>> 
>> Is there something I can do to get this working again with version 3.2.0?
>> Or is this no something that is actually supported and I was just getting
>> lucky before?
>> 
>> To help reproduce the problem I created a simple example project to
>> demonstrate this change in behavior between the two versions of the Maven
>> Archetype Plugin. The top-level pom.xml in the attach tar has the following
>> properties which you can comment/uncomment to switch between a working and
>> failing version.
>> 
>> <properties>
>>   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>>   <!-- This version of archetype plugin works -->
>> 
>> <!--<maven-archetype-plugin.verson>3.1.2</maven-archetype-plugin.verson>-->
>>   <!-- This version of archetype plugin does not work -->
>>   <maven-archetype-plugin.verson>3.2.0</maven-archetype-plugin.verson>
>> </properties>
>> 
>> If you uncompress the attached tar and call ‘mvn clean verify’ you can see
>> how it works with 3.1.2 and fails with 3.2.0.
>> 
>> Thank you for the help,
>> 
>> Matt
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Issue using common Velocity template with version 3.2.0 of Maven Archetype Plugin

Posted by Martin Kanters <ma...@apache.org>.
Hi Matt,

Thanks a lot for your extensive bug report including sample project. Could
you please create a bug in Jira? [1]
It will make it easier to pick up the issue and assign the potential fix to
a future release.

Regards, Martin

[1] https://issues.apache.org/jira/projects/ARCHETYPE/issues/

Op do 27 aug. 2020 om 21:41 schreef Matthew Compton <co...@gmail.com>:

> Hello all,
>
> The recently released version 3.2.0 of the Maven Archetype Plugin has
> broken an archetype I created. I have confirmed my archetype still works
> with version 3.1.2 of the plugin but my team and I normally run "mvn
> archetype:generate …” just so we don’t have to specify a particular version
> of the plugin, but now Maven will pick up the 3.2.0 version of the plugin
> and fail. I am aware that using "mvn
> org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate …” will work
> around the problem, but I’d still like to fix my archetype to work with the
> latest version of the plugin.
>
> The problem appears to be that something has changed with how the class
> path/resources are setup with the velocity template engine when rendering
> templates. I tried looking through the release notes but it just looks like
> version numbers were bumped, so I doesn’t seem like this was an intentional
> change in behavior.
>
> The source of the problem is my archetype has a common
> 'META-INF/common-variable-definitions.vm’ that contains variables that are
> used in multiple files within the archetype. This worked great with earlier
> versions of the archetype plugin, each template that needed the common
> variable definitions simply needed  a #parse(
> "META-INF/common-variable-definitions.vm” ) at the top of the file and then
> all of the usual replacements that were needed are available. Now, with the
> 3.2.0 version of the plugin I get the following error:
>
>
> [ERROR] ResourceManager : unable to find resource
> 'archetype-resources/META-INF/common-variable-definitions.vm' in any
> resource loader.
> [ERROR] #parse(): cannot find template
> 'archetype-resources/META-INF/common-variable-definitions.vm', called at
> archetype-resources/pom.xml[line 1, column 1]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time:  1.327 s
> [INFO] Finished at: 2020-08-26T16:28:24-07:00
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] Failed to execute goal
> org.apache.maven.plugins:maven-archetype-plugin:3.2.0:integration-test
> (default-integration-test) on project demo-archetype:
> [ERROR] Archetype IT 'basic' failed: Error merging velocity templates:
> Unable to find resource
> 'archetype-resources/META-INF/common-variable-definitions.vm'
> [ERROR] -> [Help 1]
> [ERROR]
> [ERROR] To see the full stack trace of the errors, re-run Maven with the
> -e switch.
> [ERROR] Re-run Maven using the -X switch to enable full debug logging.
> [ERROR]
> [ERROR] For more information about the errors and possible solutions,
> please read the following articles:
> [ERROR] [Help 1]
> http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
>
>
> The issue is that the Velocity engine now expects the common definitions
> file in 'archetype-resources/META-INF' instead of a top-level 'META-INF'
> directory. I tried moving the file to
> 'archetype-resources/META-INF/common-variable-definitions.vm', but I found
> that only worked for the “first level”, and it essentially expected that
> file to copied into every level of the directory hierarchy of the archetype
> resources that had templates to render, which makes trying to do this
> totally pointless, I might as well copy the definitions into the top of
> each file like I had done in a very early version of my archetype. I also
> tried using “../“ relative paths (like #parse(
> “../META-INF/common-variable-definitions.vm” )) in files deeper into the
> directory hierarchy to reference back up to a single common velocity
> template, but could not get that to work either.
>
> Is there something I can do to get this working again with version 3.2.0?
> Or is this no something that is actually supported and I was just getting
> lucky before?
>
> To help reproduce the problem I created a simple example project to
> demonstrate this change in behavior between the two versions of the Maven
> Archetype Plugin. The top-level pom.xml in the attach tar has the following
> properties which you can comment/uncomment to switch between a working and
> failing version.
>
>  <properties>
>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>    <!-- This version of archetype plugin works -->
>
>  <!--<maven-archetype-plugin.verson>3.1.2</maven-archetype-plugin.verson>-->
>    <!-- This version of archetype plugin does not work -->
>    <maven-archetype-plugin.verson>3.2.0</maven-archetype-plugin.verson>
>  </properties>
>
> If you uncompress the attached tar and call ‘mvn clean verify’ you can see
> how it works with 3.1.2 and fails with 3.2.0.
>
> Thank you for the help,
>
> Matt
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org