cobigen icon indicating copy to clipboard operation
cobigen copied to clipboard

Implement version conflict resolution for CobiGen template sets

Open Copilot opened this issue 7 months ago • 1 comments

Problem

CobiGen was unable to handle version conflicts when multiple versions of the same template set existed in the adapted folder. This caused both template sets to be loaded and processed incrementally, overwriting each other and leading to unpredictable generation results.

Solution

Implemented automatic version conflict resolution in TemplateSetConfigurationManager that:

  1. Parses POM files to extract Maven coordinates (groupId, artifactId, version) from each template set
  2. Groups template sets by groupId:artifactId combination
  3. Compares versions using semantic versioning logic to identify the latest version
  4. Filters results to return only the template set with the highest version for each group

Key Features

  • Semantic version comparison: Handles versions like "1.0", "1.1", "dev-SNAPSHOT-1", etc.
  • Snapshot handling: Prefers release versions over snapshot versions when base versions are equal
  • Robust error handling: Continues processing if individual POM parsing fails
  • Detailed logging: Debug logs show which template sets are selected/skipped and why
  • Backward compatibility: Falls back gracefully if POM parsing fails

Example

Consider two template sets in the adapted folder:

  • template-set1/pom.xml: version dev-SNAPSHOT-1
  • template-set2/pom.xml: version dev-SNAPSHOT-1.1

Before: Both template sets would be loaded, causing conflicts After: Only template-set2 (version 1.1) is loaded, with debug log:

Skipping older template set template-set1 in favor of version dev-SNAPSHOT-1.1

Testing

  • ✅ Unit tests verify version comparison logic works correctly
  • ✅ Integration tests confirm only the latest version is selected
  • ✅ Re-enabled the previously ignored system test callClassLoadingTemplateSetTestWithVersionConflict
  • ✅ Added test data with conflicting template sets to simulate real scenarios

Impact

Users can now safely have multiple versions of the same template set in their adapted folder, and CobiGen will automatically use only the latest version for code generation, ensuring consistent and predictable behavior.

Fixes #1665.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repository.sonatype.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.10/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.10/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.10 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.10/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/cobigen/cobigen org.codehaus.plexus.classworlds.launcher.Launcher clean (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Jul 10 '25 12:07 Copilot