Skip to content

cli: validate computed Java/Kotlin/Groovy package name before generating (reserved words, leading-digit segments) #105

Description

@marioserrano09

Problem

dynamia new doesn't validate that the computed Java/Kotlin/Groovy base package
(groupId + '.' + artifactId.replace(/-/g, '.')) is actually a valid package name for the
target language before generating. Two concrete failure modes found while smoke-testing the
26.9.0 release:

  1. Reserved words: --artifact-id final-java (groupId com.acme) computes base package
    com.acme.final.java -- final is a reserved word in Java/Groovy, so the generated project
    fails to compile with cryptic errors like <identifier> expected. Kotlin is unaffected since
    it treats final as a soft/contextual keyword.
  2. Leading-digit segments: --artifact-id smoke-java-2 computes base package
    com.acme.smoke.java.2 -- a package segment can't start with a digit in Java/Kotlin/Groovy.
    Fails with ';' expected (Java) or a Groovy stub-generation parse error, again with no hint
    about the actual cause.

Impact

A user picks a project name that happens to collide with a language keyword or produces an
invalid package segment, and gets a wall of mvn/compiler errors with no indication the CLI
itself is the source of the problem.

Proposed fix

In platform/packages/cli/src/commands/new.ts (or a small helper in utils/), validate the
computed base package before cloning/generating:

  • Each dot-separated segment must not be empty, must start with a letter or underscore (not a
    digit), and must not be a reserved word in the target language (Java reserved words are a
    superset that also covers Groovy; Kotlin's hard keywords are a smaller list -- soft keywords
    like final are fine to allow for Kotlin specifically).
  • On failure, show a clear message before cloning anything, e.g. --artifact-id "final-java"
    would produce an invalid package segment "final" (Java reserved word) -- pick a different
    artifact ID, and re-prompt (interactive) or exit with DT-COMMAND-003` (non-interactive).

Repro: dynamia new --name x --scaffold backend --backend-lang java --group-id com.acme --artifact-id final-java --yes --no-git, then cd x/backend && ./mvnw compile.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions