Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error:ehcache-ehcache previously defined at line 1, column 1 #100

Closed
qinkangdeid opened this issue Mar 7, 2024 · 5 comments · Fixed by #101
Closed

error:ehcache-ehcache previously defined at line 1, column 1 #100

qinkangdeid opened this issue Mar 7, 2024 · 5 comments · Fixed by #101

Comments

@qinkangdeid
Copy link

I just decided to use Gradle as my build tool and realized that catalog works really well with Gradle. I found out that Spring didn't release a usable catalog until I discovered this repository. It's awesome!! It seems to meet my needs perfectly. I tested it out and encountered an error when refreshing after configuring it. I feel like what I did is the same as your document. What caused this? Did I configure something incorrectly? Here is my demo instance. Can you take a look for me? thanks

my settings.gradle.kts config:

import dev.aga.gradle.versioncatalogs.Generator.generate

rootProject.name = "test-dependencies"

plugins {
    id("dev.aga.gradle.version-catalog-generator") version("1.4.0")
}

dependencyResolutionManagement {
    repositories {
        mavenCentral() // must include repositories here for dependency resolution to work from settings
    }
    versionCatalogs {
        generate("springLibs") { 
            from {
                from(toml("springBootDependencies"))
            }
        }
    }
}

error:

Settings file '/Users/qinkangdeid/IdeaProjects/test-dependencies/settings.gradle.kts' line: 14

ehcache-ehcache previously defined at line 1, column 1

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

* Exception is:
ehcache-ehcache previously defined at line 1, column 1 (line 1, column 1)
	at org.tomlj.MutableTomlTable.set(MutableTomlTable.java:264)
	at org.tomlj.MutableTomlTable.set(MutableTomlTable.java:243)
	at org.tomlj.TomlContainer.addLibrary(TomlContainer.kt:37)
	at dev.aga.gradle.versioncatalogs.Generator.createLibrary$plugin(Generator.kt:302)
	at dev.aga.gradle.versioncatalogs.Generator.loadDependencies$plugin(Generator.kt:242)
	at dev.aga.gradle.versioncatalogs.Generator.loadBom$plugin(Generator.kt:182)
	at dev.aga.gradle.versioncatalogs.Generator$generate$2.execute(Generator.kt:116)
	at dev.aga.gradle.versioncatalogs.Generator$generate$2.execute(Generator.kt:108)
	at org.gradle.internal.management.DefaultVersionCatalogBuilderContainer.lambda$create$0(DefaultVersionCatalogBuilderContainer.java:76)
	at org.gradle.api.internal.catalog.DefaultVersionCatalogBuilder.withContext(DefaultVersionCatalogBuilder.java:173)
	at org.gradle.internal.management.DefaultVersionCatalogBuilderContainer.lambda$create$1(DefaultVersionCatalogBuilderContainer.java:76)
	at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(AbstractNamedDomainObjectContainer.java:80)
	at org.gradle.internal.management.DefaultVersionCatalogBuilderContainer.create(DefaultVersionCatalogBuilderContainer.java:73)
	at org.gradle.internal.management.DefaultVersionCatalogBuilderContainer.create(DefaultVersionCatalogBuilderContainer.java:42)
	at dev.aga.gradle.versioncatalogs.Generator.generate$plugin(Generator.kt:108)
	at dev.aga.gradle.versioncatalogs.Generator.generate$plugin(Generator.kt:76)
	at dev.aga.gradle.versioncatalogs.Generator.generate(Generator.kt:61)
	at Settings_gradle$1$2.execute(settings.gradle.kts:14)
	at Settings_gradle$1$2.execute(settings.gradle.kts:13)
	at org.gradle.internal.management.DefaultDependencyResolutionManagement.versionCatalogs(DefaultDependencyResolutionManagement.java:132)
	at Settings_gradle$1.execute(settings.gradle.kts:13)
	at Settings_gradle$1.execute(settings.gradle.kts:9)
	at org.gradle.initialization.DefaultSettings.dependencyResolutionManagement(DefaultSettings.java:388)
	at Settings_gradle.<init>(settings.gradle.kts:9)

my demo:
test-dependencies.zip

@austinarbor
Copy link
Owner

@qinkangdeid glad you found the project! It looks like you're using spring 2.7.x, to be honest I've only tested with 3.X since v2 is EOL. Appreciate you providing the sample project, I'll look into this tonight and let you know what I find

@austinarbor
Copy link
Owner

austinarbor commented Mar 7, 2024

@qinkangdeid the reason for the error is because if you look at spring-boot-dependencies:2.7.18 they have declared basically two different versions of the same artifact

<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache</artifactId>
  <version>${ehcache.version}</version>
</dependency>
<dependency>
  <groupId>org.ehcache</groupId>
  <artifactId>ehcache</artifactId>
  <version>${ehcache3.version}</version>
</dependency>

Based on how we generated the aliases by default, these create the conflicting entries ehcache-ehcache.

You can fix this with a simple change in the config in your settings.gradle.kts

versionCatalogs {
  generate("springLibs") {
    from(toml("springBootDependencies"))
    aliasPrefixGenerator =  { groupId, artifactId ->
      if(groupId == "org.ehcache") {
        "ehcache3"
      } else {
        GeneratorConfig.DEFAULT_ALIAS_PREFIX_GENERATOR(groupId, artifactId)
      }
    }
  }
}

This will give you springLibs.ehcache... for the entries which have the groupId net.sf.ehcache, and springLibs.ehcache3... for the entries that have the groupId org.ehcache. You can of course change this to any other behavior you prefer instead.

I could do a better job of adding some pre-check analysis for better error messaging, and maybe change the name generation algorithm if possible when conflicting entries like this arise, but for the time being this would be the only fix.

Let me know if you have any questions!

@qinkangdeid
Copy link
Author

Oh, I see! I didn't realize that spring-boot-dependencies would have two ehcache versions. I understand now.

When naming conflicts occur:

  1. Also provide a ⚠️ warning message in the console
    Provide a clear warning message to better help developers understand the situation and know how to handle it.

  2. Provide a default generated name
    The default generated name could combine the group and artifact in camelCase? Developers can use it directly if they accept, and if not, they can easily see the warning and customize the name as shown above.

@austinarbor
Copy link
Owner

austinarbor commented Mar 8, 2024

I will be merging this PR soon and I'll cut 1.4.1. This should resolve the first item above. The new error will be:

Attempting to register a library with the alias ehcache-ehcache but the alias already exists.
    Existing: net.sf.ehcache:ehcache:ehcache
  Attempting: org.ehcache:ehcache:ehcache3
Please check the source BOM and either exclude the conflict or provide custom prefix/suffix generators.

The second item above will take more work/thought

@austinarbor
Copy link
Owner

@qinkangdeid PR has been merged and 1.4.1 is published to Gradle now

@austinarbor austinarbor linked a pull request Mar 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants