ktorio / ktor-init-tools

ktor project generator web page and IDEA plugin

Home Page:https://start.ktor.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicate Maven Dependencies with scope "test" cause build failures

ptrxwsmitt opened this issue · comments

Hi,
I just tried to create a sample Project using IntelliJ with the KTor Init Tools.

Creating any Project led to having most dependencies twice in my pom.xml, such as "ktor-server-core" .
One without scope, one with scope "test".
This causes maven to use the test-scoped dependencies only and it won't build the sample application which is not in the test-scope.
Removing the duplictes makes the application build as supposed.

Please provide the dependencies just once in the pom.xml without a scope.
Regards Patrick

Just tried it and it seems to work well, no duplication generated. Tested both IDEA plugin and start.ktor.io

I managed to reproduce the issue and will describe it more detailled:
IntelliJ IDEA 2018.2.5 Community Edition on Windows 10 + KTOR Plugin 0.3.4 + Bundled Maven 3.3.9:

  1. Generated a Maven Project with Netty, KTOR 1.0.0-beta-3. I also enabled the Wrapper-Checkbox.
  2. I selected a few additional Server-Dependencies (Freemarker + Static Content + Metrics).

This leads to a pom.xml that contains one normal dependency and one dependency with scope "test" for each additional ktor-dependency except the netty dependency.

Example:

...
        <dependency>
            <groupId>io.ktor</groupId>
            <artifactId>ktor-server-core</artifactId>
            <version>${ktor_version}</version>
        </dependency>
...
        <dependency>
            <groupId>io.ktor</groupId>
            <artifactId>ktor-server-core</artifactId>
            <version>${ktor_version}</version>
            <scope>test</scope>
        </dependency>
...

This leads to the following error on "mvn clean install":

...
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: io.ktor:ktor-server-core:jar -> duplicate declaration of version ${ktor_version} @ line 79, column 21
...
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
...
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.0:compile (compile) on project example: Compilation failure: Compilation failure:
[ERROR] C:\Users\neo\IdeaProjects\init-test\src\Application.kt:[3,16] Unresolved reference: application

When I manually remove all test-dependencies that already exist as non-test-dependencies, the build works well.

I'd recommend removing the duplicate test-dependencies from the generated pom.xml, as these are already available as non-test-dependencies and therefore are not needed.

Maybe it's already fixed with the newer version but I'd be glad if you'd check it.

Most likely it is fixed already in the latest plugin 1.0.0

Fix confirmed. Version 1.0.0 works. Good work.