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

Helidon MP Quickstart Gradle improvements #2190

Closed
aalmiray opened this issue Jul 17, 2020 · 2 comments
Closed

Helidon MP Quickstart Gradle improvements #2190

aalmiray opened this issue Jul 17, 2020 · 2 comments
Assignees
Labels
bug Something isn't working examples P3

Comments

@aalmiray
Copy link

aalmiray commented Jul 17, 2020

Environment Details

  • Helidon Version: 2.0.1
  • Helidon MP
  • JDK version: N/A
  • OS: N/A
  • Docker version: N/A

Problem Description

The Gradle Quickstart from Helidon MP 2.0.1 is missing a few things

  1. Apply the org.kordamp.gradle.jandex plugin to generate the jandex.idx file.
  2. The value of main class is wrong, it should be io.helidon.microprofile.cdi.Main.
  3. Dependencies are wrong, javax.activation -> jakarta.activation
  4. enforcedPlatform() must be used instead of platform() otherwise some dependencies will be upgraded and that causes trouble.
  5. It looks like org.glassfish.hk2.external:jakarta.inject:2.6.1 causes trouble as it provides duplicate classes. This dependency must be excluded.

It might be a good idea to configure the Gradle enforcer plugin to detect this case. Add the BanDuplicateClasses enforcer rule to the Helidon build (Maven) to detect duplicate classes.

The following Gradle build provides fixes for the aforementioned issues and could be used a starting point

plugins {
    id 'com.github.johnrengelman.shadow'
    id 'java'
    id 'org.kordamp.gradle.jandex'
}
 
repositories {
    jcenter()
}
 
dependencies {
    implementation enforcedPlatform("io.helidon:helidon-dependencies:${helidonVersion}")
    implementation('io.helidon.microprofile.bundles:helidon-microprofile') {
        exclude group: 'org.glassfish.hk2.external', module: 'jakarta.inject'
    }
 
    runtimeOnly 'org.jboss:jandex'
    runtimeOnly 'jakarta.activation:jakarta.activation-api'
 
    testImplementation 'org.junit.jupiter:junit-jupiter-api'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
 
test {
    useJUnitPlatform()
}
 
// define a custom task to copy all dependencies in the runtime classpath
// into build/libs/libs
// uses built-in Copy
task copyLibs(type: Copy) {
    from configurations.runtimeClasspath
    into 'build/libs/libs'
}
 
// add it as a dependency of built-in task 'assemble'
copyLibs.dependsOn jar
assemble.dependsOn copyLibs
 
// default jar configuration
// set the main classpath
// add each jar under build/libs/libs into the classpath
jar {
    manifest {
        attributes ('Main-Class': 'io.helidon.microprofile.cdi.Main',
            'Class-Path': configurations.runtimeClasspath.files.collect { "libs/$it.name" }.join(' ')
        )
    }
}

Note that this build does not rely on the application plugin just yet (as shown in #2186 for Helidon SE). Packaging and running an application can be done by invoking

$ gradle assemble
$ java -jar build/libs/${project.name}-${project.version}.jar
@barchetta barchetta added bug Something isn't working examples P3 labels Jul 23, 2020
@barchetta barchetta self-assigned this Jul 23, 2020
@barchetta
Copy link
Member

Some of this addressed by PR #2214

@barchetta
Copy link
Member

Since the PR fixed the most serious of the issues listed here I'm going to close this and use issue #2219 to track additional improvements to the quickstart example gradle files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working examples P3
Projects
Archived in project
Development

No branches or pull requests

2 participants