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

<addDependencies> does not add runtime scope #5

Closed
javaboy79 opened this issue Feb 21, 2014 · 33 comments
Closed

<addDependencies> does not add runtime scope #5

javaboy79 opened this issue Feb 21, 2014 · 33 comments

Comments

@javaboy79
Copy link
Contributor

With addDependencies=true dependencies set with a 'runtime' scope do not seem to be added to the classpath. The resulting .exe cannot find these dependencies. If you run with mvn -X you can see where the dependencies lists no runtime scopes.

@lukaszlenart
Copy link
Collaborator

I have been using this plugin very long ago, can you prepare a small demo project that I can use and test the solution?

@javaboy79
Copy link
Contributor Author

Please find a sample of the problem here:
https://github.com/javaboy79/samples.git

there are instructions and details in the README

@lukaszlenart
Copy link
Collaborator

Just tested your example and everything works as expected, see the screenshot
2014-09-30_0749

@fxnn
Copy link

fxnn commented Oct 9, 2014

That's right, the file is included, but not referenced by the EXE file! Try to open it with any binary-enabled editor and search for JAR file names. You'll find that compile scoped dependencies are right there, but runtime scoped ones are missing.

This leads to the problem that the JAR is included as a file, but not in the effective classpath.

@lukaszlenart lukaszlenart reopened this Oct 10, 2014
@lukaszlenart
Copy link
Collaborator

The problem is with @parameter default-value="${project.artifacts}" where artifacts are defined as follow:

    /**
     * All dependencies that this project has, including transitive ones.
     * Contents are lazily populated, so depending on what phases have run dependencies in some scopes won't be included.
     * eg. if only compile phase has run, dependencies with scope test won't be included. 
     * @return {@link Set} &lt; {@link Artifact} >
     * @see #getDependencyArtifacts() to get only direct dependencies
     */

which means dependencies are evaluated based on current phase, but what is funny

[DEBUG]   (s) projectArtifactMap = {org.slf4j:slf4j-api=org.slf4j:slf4j-api:jar:1.7.5:compile, org.apache.logging.log4j:log4j-core=org.apache.logging.log4j:log4j-core:jar:2.0-rc1:runtime, org.apache.logging.log4j:log4j-api=org.apache.logging.log4j:log4j-api:jar:2.0-rc1:runtime, org.apache.logging.log4j:log4j-slf4j-impl=org.apache.logging.log4j:log4j-slf4j-impl:jar:2.0-rc1:runtime}

so I must find a way to include that map in classpath resolution ;-)

@lukaszlenart
Copy link
Collaborator

Done, please check the latest 1.7-SNAPSHOT version, it should be available in 30 min in Maven Central

@lukaszlenart
Copy link
Collaborator

Don't wait for Maven Central - use OSS Sonatype repo, details in README.md

@virgo47
Copy link

virgo47 commented Apr 20, 2015

We're using version 1.7.1 and we have exactly the same problem. With runtime it is not on the classpath when EXE runs.

Our setup of the plugin is like this:

<plugin>
    <groupId>com.akathist.maven.plugins.launch4j</groupId>
    <artifactId>launch4j-maven-plugin</artifactId>
    <version>1.7.1</version>
    <executions>
        <execution>
            <id>l4j-clui</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>console</headerType>
                <jar>
                    ${project.build.directory}/${project.artifactId}-${project.version}.jar
                </jar>
                <dontWrapJar>false</dontWrapJar>
                <outfile>${project.build.directory}/${executable.name}.exe
                </outfile>
                <classPath>
                    <mainClass>${mainClass.name}</mainClass>
                    <!-- using this will set strict classpath dependencies, even when there are more JARs in
                    the directory - don't use <preCp>dependency_libs/*.jar</preCp> because that may cause
                    auto-discovery of unwanted components from other modules when single dependency_libs
                    contains union of all needed JARs (typical production setup) -->
                    <jarLocation>dependency_libs/</jarLocation>
                </classPath>
                <chdir>.</chdir>
                <icon>src/main/resources/${executable.name}.ico</icon>
                <jre>
                    <minVersion>1.8.0</minVersion>
                    <opts>
                        <opt>-showversion</opt>
                    </opts>
                    <jdkPreference>jdkOnly</jdkPreference>
                </jre>
                <versionInfo>
                    <fileVersion>1.0.0.0</fileVersion>
                    <txtFileVersion>${project.version}</txtFileVersion>
                    <fileDescription>${project.name}</fileDescription>
                    <copyright>2014 xxx</copyright>
                    <productVersion>1.0.0.0</productVersion>
                    <txtProductVersion>1.0.0.0</txtProductVersion>
                    <productName>${project.name}</productName>
                    <companyName>xxx</companyName>
                    <internalName>xxx</internalName>
                    <originalFilename>${executable.name}.exe
                    </originalFilename>
                </versionInfo>
            </configuration>
        </execution>
    </executions>
</plugin>

@lukaszlenart
Copy link
Collaborator

@virgo47 can you run this command and post result?

mvn dependency:list -DincludeScope=runtime

@virgo47
Copy link

virgo47 commented Apr 21, 2015

Here it is, with minor anonymization, but groovy-all is pretty much self-contained, so it should not change the result. However, I checked the EXE file too, and there is the line that contains all the JARs (I didn't count them though :-)), but the groovy-all one. That one is missing and is NOT listed in the EXE file.

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.9:list (default-cli) @ restmod ---
[INFO] 
[INFO] The following files have been resolved:
[INFO]    com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.2:compile
[INFO]    org.testng:testng:jar:6.8.13:compile
[INFO]    org.springframework:spring-orm:jar:4.1.4.RELEASE:compile
[INFO]    org.springframework:spring-context:jar:4.1.4.RELEASE:compile
[INFO]    org.glassfish.hk2:hk2-config:jar:2.3.0-b10:compile
[INFO]    org.eclipse.jetty:jetty-io:jar:9.2.8.v20150217:compile
[INFO]    org.eclipse.jetty:jetty-xml:jar:9.2.8.v20150217:compile
[INFO]    aopalliance:aopalliance:jar:1.0:compile
[INFO]    org.eclipse.jetty:jetty-http:jar:9.2.8.v20150217:compile
[INFO]    com.googlecode.juniversalchardet:juniversalchardet:jar:1.0.3:compile
[INFO]    org.eclipse.jdt.core.compiler:ecj:jar:4.3.1:compile
[INFO]    org.jasypt:jasypt:jar:1.9.0:compile
[INFO]    org.javasimon:javasimon-console-embed:jar:4.0.0:compile
[INFO]    com.beust:jcommander:jar:1.35:compile
[INFO]    org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.13:compile
[INFO]    com.fasterxml.jackson.core:jackson-databind:jar:2.4.4:compile
[INFO]    org.slf4j:slf4j-api:jar:1.7.8:compile
[INFO]    org.eclipse.jetty:jetty-server:jar:9.2.8.v20150217:compile
[INFO]    org.eclipse.persistence:org.eclipse.persistence.jpa:jar:2.5.2:compile
[INFO]    org.apache.poi:poi-scratchpad:jar:3.11:compile
[INFO]    org.apache.activemq:activemq-core:jar:5.7.0:compile
[INFO]    commons-digester:commons-digester:jar:2.1:compile
[INFO]    commons-io:commons-io:jar:2.4:compile
[INFO]    commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO]    org.javasimon:javasimon-core:jar:4.0.0:compile
[INFO]    com.mysema.commons:mysema-commons-lang:jar:0.2.4:compile
[INFO]    javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO]    org.apache.poi:poi-ooxml-schemas:jar:3.11:compile
[INFO]    com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.3.2:compile
[INFO]    org.glassfish.hk2.external:aopalliance-repackaged:jar:2.3.0-b10:compile
[INFO]    org.eclipse.persistence:org.eclipse.persistence.asm:jar:2.5.2:compile
[INFO]    org.glassfish.hk2:hk2:jar:2.3.0-b10:compile
[INFO]    org.glassfish.hk2:spring-bridge:jar:2.3.0-b10:compile
[INFO]    org.jvnet:tiger-types:jar:1.4:compile
[INFO]    javax.jms:jms-api:jar:1.1-rev-1:compile
[INFO]    org.glassfish.jersey.containers:jersey-container-servlet:jar:2.13:compile
[INFO]    javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO]    ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO]    commons-validator:commons-validator:jar:1.4.0:compile
[INFO]    org.glassfish.hk2:hk2-api:jar:2.3.0-b10:compile
[INFO]    org.eclipse.jetty:jetty-util:jar:9.2.8.v20150217:compile
[INFO]    org.glassfish.hk2:hk2-locator:jar:2.3.0-b10:compile
[INFO]    org.glassfish.hk2:hk2-utils:jar:2.3.0-b10:compile
[INFO]    com.zaxxer:HikariCP:jar:2.2.5:compile
[INFO]    org.glassfish.jersey.core:jersey-server:jar:2.14:compile
[INFO]    org.beanshell:bsh:jar:2.0b4:compile
[INFO]    javax.mail:mail:jar:1.4.5:compile
[INFO]    commons-lang:commons-lang:jar:2.6:compile
[INFO]    org.glassfish.hk2:hk2-runlevel:jar:2.3.0-b10:compile
[INFO]    com.mysema.codegen:codegen:jar:0.6.5:compile
[INFO]    org.eclipse.jetty:jetty-servlet:jar:9.2.8.v20150217:compile
[INFO]    org.eclipse.persistence:org.eclipse.persistence.antlr:jar:2.5.2:compile
[INFO]    com.google.code.findbugs:jsr305:jar:2.0.3:compile
[INFO]    org.apache.poi:poi-ooxml:jar:3.11:compile
[INFO]    org.glassfish.hk2.external:javax.inject:jar:2.4.0-b06:compile
[INFO]    org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
[INFO]    javax.activation:activation:jar:1.1.1:compile
[INFO]    org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.14:compile
[INFO]    commons-codec:commons-codec:jar:1.10:compile
[INFO]    org.javassist:javassist:jar:3.18.1-GA:compile
[INFO]    javax.mail:javax.mail-api:jar:1.5.2:compile
[INFO]    org.apache.poi:poi:jar:3.11:compile
[INFO]    org.apache.commons:commons-email:jar:1.3.3:compile
[INFO]    javax.inject:javax.inject:jar:1:compile
[INFO]    com.mysema.querydsl:querydsl-jpa:jar:3.6.0:compile
[INFO]    com.sun.mail:javax.mail:jar:1.5.2:compile
[INFO]    net.sourceforge.jtds:jtds:jar:1.3.1:compile
[INFO]    org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO]    org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
[INFO]    org.springframework.security:spring-security-web:jar:3.2.5.RELEASE:compile
[INFO]    org.glassfish.jersey.ext:jersey-spring3:jar:2.13:compile
[INFO]    org.glassfish.jersey.media:jersey-media-multipart:jar:2.13:compile
[INFO]    org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec:jar:1.0.1:compile
[INFO]    org.glassfish.jersey.core:jersey-client:jar:2.13:compile
[INFO]    org.eclipse.jetty:jetty-webapp:jar:9.2.8.v20150217:compile
[INFO]    org.glassfish.hk2:config-types:jar:2.3.0-b10:compile
[INFO]    org.apache.activemq.protobuf:activemq-protobuf:jar:1.1:compile
[INFO]    org.springframework:spring-jdbc:jar:4.1.4.RELEASE:compile
[INFO]    org.springframework:spring-core:jar:4.1.4.RELEASE:compile
[INFO]    com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile
[INFO]    org.glassfish.hk2.external:bean-validator:jar:2.3.0-b10:compile
[INFO]    org.slf4j:jcl-over-slf4j:jar:1.7.8:compile
[INFO]    org.eclipse.persistence:javax.persistence:jar:2.1.0:compile
[INFO]    org.glassfish.hk2:core:jar:2.3.0-b10:compile
[INFO]    com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.4.2:compile
[INFO]    org.springframework:spring-web:jar:4.1.4.RELEASE:compile
[INFO]    com.google.guava:guava:jar:17.0:compile
[INFO]    com.mysema.querydsl:querydsl-apt:jar:3.6.0:compile
[INFO]    com.mysema.querydsl:querydsl-core:jar:3.6.0:compile
[INFO]    org.eclipse.persistence:org.eclipse.persistence.core:jar:2.5.2:compile
[INFO]    org.springframework.data:spring-data-jpa:jar:1.7.1.RELEASE:compile
[INFO]    org.springframework.security:spring-security-config:jar:3.2.5.RELEASE:compile
[INFO]    org.eclipse.jetty:jetty-security:jar:9.2.8.v20150217:compile
[INFO]    org.springframework:spring-tx:jar:4.1.4.RELEASE:compile
[INFO]    org.springframework.security:spring-security-core:jar:3.2.5.RELEASE:compile
[INFO]    ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO]    org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
[INFO]    xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO]    com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile
[INFO]    org.glassfish.hk2:class-model:jar:2.3.0-b10:compile
[INFO]    javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO]    org.jvnet.mimepull:mimepull:jar:1.9.3:compile
[INFO]    org.codehaus.groovy:groovy-all:jar:2.4.3:runtime
[INFO]    org.javasimon:javasimon-javaee:jar:4.0.0:compile
[INFO]    org.eclipse.persistence:org.eclipse.persistence.jpa.jpql:jar:2.5.2:compile
[INFO]    com.mysema.querydsl:querydsl-codegen:jar:3.6.0:compile
[INFO]    org.glassfish.hk2.external:asm-all-repackaged:jar:2.3.0-b10:compile
[INFO]    org.aspectj:aspectjrt:jar:1.8.4:compile
[INFO]    org.javasimon:javasimon-spring:jar:4.0.0:compile
[INFO]    org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.13:compile
[INFO]    commons-collections:commons-collections:jar:3.2.1:compile
[INFO]    javax:javaee-api:jar:7.0:compile
[INFO]    org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
[INFO]    javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO]    org.glassfish.jersey.core:jersey-common:jar:2.13:compile
[INFO]    org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO]    com.infradna.tool:bridge-method-annotation:jar:1.13:compile
[INFO]    org.springframework.data:spring-data-commons:jar:1.9.1.RELEASE:compile
[INFO]    org.apache.mina:mina-core:jar:2.0.7:compile
[INFO]    org.aspectj:aspectjweaver:jar:1.8.4:compile
[INFO]    xpp3:xpp3:jar:1.1.4c:compile
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.167 s
[INFO] Finished at: 2015-04-21T11:29:21+01:00
[INFO] Final Memory: 15M/38M
[INFO] ------------------------------------------------------------------------

@lukaszlenart
Copy link
Collaborator

So the problem is that the groovy-all is missing but all other runtime dependencies are in place, do I get it right?

@virgo47
Copy link

virgo47 commented Apr 22, 2015

We have only this as runtime dep. When I switch it to default scope (or explicitly compile) it is mentioned in the EXE, in runtime scope it is not. I doubt it has anything to do with name of the JAR. Sorry for not being clear, the rest of my deps is not runtime and they cause no problem.

@lukaszlenart
Copy link
Collaborator

No I'm lost :)

Can you share detailed dependencies of your project? Or prepare a small demo app to reproduce this issue?

virgo47 added a commit to virgo47/litterbin that referenced this issue Apr 22, 2015
@virgo47
Copy link

virgo47 commented Apr 22, 2015

Here it is: https://github.com/virgo47/litterbin/tree/master/issues/l4jissue
One class, one POM, mvn package, run the target/xxx.exe and you will see whether Groovy script engine is (or is not) on the classpath. See the comment in POM dependency for groovy.

@lukaszlenart
Copy link
Collaborator

Great! Now I see you have put groovy-all explicit in runtime scope, maybe that's the issue, will investigate :)

@virgo47
Copy link

virgo47 commented Apr 22, 2015

Sorry, I implied this information from the title and first post of the original bug because it exactly matched my situation. My bad for not being clear enough. From here it looked like reopen, if it's not let me know if I should start a new bug.

@lukaszlenart
Copy link
Collaborator

f575af6 should solve the problem, can you test 1.7.6-SNAPSHOT? If it passes, I will push a new version to the Central.

@virgo47
Copy link

virgo47 commented Apr 27, 2015

How can I try the snapshot? Snapshot wasn't found in repo automatically and when I downloaded the zip of the project and tried mvn install it failed with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor (default-descriptor) on project launch4j-maven-plugin: Error extracting plugin descriptor: 'No mojo definitions were found for plugin: com.akathist.maven.plugins.launch4j:launch4j-maven-plugin.' -> [Help 1]

I tried both repositories and pluginRepositories like this:

    <pluginRepositories>
        <pluginRepository>
            <id>sonatype-nexus-snapshots</id>
            <name>Sonatype Nexus Snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <repositories>
        <repository>
            <id>sonatype-nexus-snapshots</id>
            <name>Sonatype Nexus Snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

@lukaszlenart
Copy link
Collaborator

Sorry, forget to push - try now

@virgo47
Copy link

virgo47 commented Apr 27, 2015

Yup, 1.7.6-SNAPSHOT finds groovy dependency in runtime scope, and running exe will find groovy script engine without problems now. 👍

@lukaszlenart
Copy link
Collaborator

Gut! I will push a new version soon! Thanks for your support!

@lukaszlenart
Copy link
Collaborator

New artifacts underway to the Central - please wait 24h for sync :) Enjoy!

@virgo47
Copy link

virgo47 commented Apr 27, 2015 via email

@javaboy79
Copy link
Contributor Author

This is working partially. It does not pick up transitive runtime dependencies. Can this be reopened to address the problem?

e.g.

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <scope>runtime</scope>
</dependency>

This gets correctly added to the exe, but this dependency has a runtime dependency on log4j-api which is not added to the exe.

@javaboy79
Copy link
Contributor Author

Also, the runtime dependencies are just added to the end of the classpath. They should be in pom/maven order as the rest of them are.

@lukaszlenart
Copy link
Collaborator

@javaboy79 not sure if I understand, I thought it was already solved and this commit f575af6 just extended it, did I miss something?

@javaboy79
Copy link
Contributor Author

There are at least two issues here, the first is more critical:

  1. Transitive dependencies of runtime scope are not added to the classpath. (see log4j example above)
  2. Runtime dependencies are just added to the end of the classpath, which does not accurately reflect the pom order. This can lead to unpredictable classloading issues if two jars share the same classes.

@javaboy79
Copy link
Contributor Author

Pull request #24 submitted. It fixes both issues.

@lukaszlenart
Copy link
Collaborator

Just merged the PR #24 and pushed new SNAPSHOT version to Sonatype. Please check if everything works and I will prepare a new release afterwards

@javaboy79
Copy link
Contributor Author

@lukaszlenart Is there a special way to access snapshots? I do not see this in the repo.

@javaboy79
Copy link
Contributor Author

@lukaszlenart Nevermind my previous comment, I figured out where the snapshot repo was. Yes, everything seems to be working as expected with the snapshot release.

@lukaszlenart
Copy link
Collaborator

Everything is in README

@lukaszlenart
Copy link
Collaborator

Time to release :)

thomas3 pushed a commit to thomas3/launch4j-maven-plugin that referenced this issue Nov 29, 2015
thomas3 added a commit to thomas3/launch4j-maven-plugin that referenced this issue Nov 29, 2015
…en-plugin

* 'master' of https://github.com/lukaszlenart/launch4j-maven-plugin: (91 commits)
  Adds example wit opts
  Adds version notes
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release launch4j-maven-plugin-1.7.8
  Migrates to new Tarvis infrastructure
  Use ProcessBuilder to launch 'chmod'
  Corrects small type
  Adds additional info about changes in 1.7.7
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release launch4j-maven-plugin-1.7.7
  Adds version notes for 1.7.7
  Uses the latest stable version of Launch4j Closes orphan-oss#21
  Adds support for bundledJreAsFallback property Closes orphan-oss#23
  Upgrades to latest snapshot version of Launch4j
  fixes for runtime scoped jars issue#5
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release launch4j-maven-plugin-1.7.6
  Adds version notes of 1.7.6
  Includes all direct dependencies closes orphan-oss#5
  Adds 1.7.5 version notes
  ...

# Conflicts:
#	.gitignore
#	.travis.yml
#	README
#	README.md
#	pom.xml
#	src/main/java/com/akathist/maven/plugins/launch4j/ClassPath.java
#	src/main/java/com/akathist/maven/plugins/launch4j/Jre.java
#	src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java
#	src/main/resources/README
#	src/main/resources/README.adoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants