apache / apache/maven-archetype
[ARCHETYPE-612] Required property interactive prompt ordering incorrect when reassigning default for a "core" property
- Dominant language
- Java
- Stars
- 148
- Forks
- 181
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 8
Description
**[David Hutchison](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=dhutchison)** opened **[ARCHETYPE-612](https://issues.apache.org/jira/browse/ARCHETYPE-612?redirect=false)** and commented
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
```java
com.devwithimagination
test-${a-prop}
${groupId}.${artifactId}.${z-prop}
```
Running this archetype interactively will output something like this:
```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':
```
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.
---
**Affects:** 3.2.0
**Remote Links:**
- [GitHub Pull Request #61
](https://github.com/apache/maven-archetype/pull/61)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the failing RequiredPropertyComparatorTest and inspect the required-property comparator involved in interactive archetype generation. Use the archetype-metadata.xml example to reproduce the ordering, then verify that properties referenced by defaults are prompted before dependent properties, including core properties such as package.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100