You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "David Hutchison (Jira)" <ji...@apache.org> on 2020/12/29 01:14:00 UTC

[jira] [Commented] (ARCHETYPE-612) Required property interactive prompt ordering incorrect when reassigning default for a "core" property

    [ https://issues.apache.org/jira/browse/ARCHETYPE-612?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17255760#comment-17255760 ] 

David Hutchison commented on ARCHETYPE-612:
-------------------------------------------

Thinking about this more, this feature to sort was clearly added for some reason so removing it would be a breaking change now (as much as that would be simpler). 

I've got a (hopefully) better solution in [this branch|https://github.com/dhutchison/maven-archetype/tree/bug/archetype-612-sort-required-properties] (I'll create a PR for it later on). This will use the order defined by the archetype order, unless it detects that there are dependencies which are in the wrong order. If there are properties in the wrong order, it will perform a sort using some graph traversal to find one that works. It is a bit of a simplistic implementation but it passes tests for my problem case and the original sort tests which were already in the project. 

> Required property interactive prompt ordering incorrect when reassigning default for a "core" property
> ------------------------------------------------------------------------------------------------------
>
>                 Key: ARCHETYPE-612
>                 URL: https://issues.apache.org/jira/browse/ARCHETYPE-612
>             Project: Maven Archetype
>          Issue Type: Bug
>          Components: Plugin
>    Affects Versions: 3.2.0
>            Reporter: David Hutchison
>            Priority: Minor
>
> The interactive archetype project generation attempts to be smart in ordering required properties so that when a default value for one property includes a reference to another, they are asked for in the correct order. This also however tries to ask the "core" properties (groupId, archetypeId, version, and package) in a fixed order, and any others in alphabetical order, if they do not have dependencies. 
>  
> I was trying to setup an archetype with a couple of prompts which would be referenced in the default values for groupId, archetypeId and package. Basically attempting to standardise the setup for these based on the "application" and "database" the repository was for, so we would have:
>  * groupId: {{com.example.${application}.data}}
>  * archetypeId: {{${database}}}
>  * package: {{com.example.${application}.data.${database}}}
>  
> When doing this however, the package is prompted for before the value it's default depends on. 
>  
> This snippet from archetype-metadata.xml will trigger the issue as a test
> {code:java}
>   <requiredProperties>
>     <requiredProperty key="a-prop"/>
>     <requiredProperty key="groupId">
>       <defaultValue>com.devwithimagination</defaultValue>
>     </requiredProperty>
>     <requiredProperty key="artifactId">
>       <defaultValue>test-${a-prop}</defaultValue>
>     </requiredProperty>
>     <requiredProperty key="package">
>       <defaultValue>${groupId}.${artifactId}.${z-prop}</defaultValue>
>     </requiredProperty>
>     <requiredProperty key="z-prop"/>
>   </requiredProperties>
> {code}
> Running this archetype interactively will output something like this:
> {code:java}
> $ mvn archetype:generate -DarchetypeArtifactId=archetype-test -DarchetypeGroupId=com.devwithimagination.archetypes
> [INFO] Generating project in Interactive mode
> [INFO] Archetype [com.devwithimagination.archetypes:archetype-test:1.0-SNAPSHOT] found in catalog local
> [INFO] Using property: groupId = com.devwithimagination
> Define value for property 'version' 1.0-SNAPSHOT: : 
> Define value for property 'package' com.devwithimagination.archetypes.archetype-test.${z-prop}: : 
> Define value for property 'a-prop': 123
> Define value for property 'artifactId' test-123: : 
> Define value for property 'z-prop': 
> {code}
> So {{package}} was prompted for before {{artifactId}} and {{z-prop}} which it needed for the default value. In typing this up I just noticed it used the {{archetypeArtifactId}} in the default value instead. 
> I have got a failing test case for {{RequiredPropertyComparatorTest}} which shows the comparator isn't performing the sort correctly. 
> A possible solution for this could be what ARCHETYPE-443 proposed, and respect the property order defined in the archetype metadata file. Any "core" required properties could still be prompted for in their default order, unless the archetype author had also included them in {{archetype-metadata.xml}}. With that change, it would be up to the archetype author to ensure that properties are correctly ordered. ARCHETYPE-562 points to other issues with this sort.
> I have been having a look at making the sort smarter, but so far I've not been able to keep the name based ordering working while fixing the property dependency based sort. 
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)