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

Add support for runtime and provided dependencies at same time #60

Closed
rehevkor5 opened this issue Jul 27, 2016 · 17 comments · Fixed by #61
Closed

Add support for runtime and provided dependencies at same time #60

rehevkor5 opened this issue Jul 27, 2016 · 17 comments · Fixed by #61

Comments

@rehevkor5
Copy link
Contributor

As discussed here http://stackoverflow.com/questions/6418414/maven-exec-plugin-cant-depend-on-provided-dependancy#comment48129503_16042080 there is no way to use the plugin while getting both provided and runtime dependencies onto the classpath.

@khmarbaise
Copy link
Member

Based on the answer on SO it does not make sense. Or you you could provide a patch (as PR) ?

@rehevkor5
Copy link
Contributor Author

Try using the below POM along with a main class called "Main".

If you run mvn exec:java -P runtime, you get:

java.lang.NoClassDefFoundError: org/apache/log4j/Level

indicating that the "provided" dependency is not available.

If you run mvn exec:java -P compile, you get:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

indicating that the "runtime" dependency is not available.

I can attempt to make a PR to help fix this, but I could use some input on what the configuration should look like. Should we add a new value for "classpathScope" called "provided" which includes both runtime and provided?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.nnoncarey.sha</groupId>
    <artifactId>maven-exec-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.21</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.5.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>runtime</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <mainClass>Main</mainClass>
                            <executable>java</executable>
                            <classpathScope>runtime</classpathScope>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>compile</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <mainClass>Main</mainClass>
                            <executable>java</executable>
                            <classpathScope>compile</classpathScope>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

@khmarbaise
Copy link
Member

I know that the provided scope is not available on the classpath cause it's defined provided which means it is provided by the runtime environment. That was the reason that i said you could provide a patch which solves this problem ?

@rehevkor5
Copy link
Contributor Author

Oh, it sounded like you thought it made no sense. I can attempt a patch, but as I asked above, do you care what the configuration setting should be? Is "provided" ok as a new value for classpathScope?

rehevkor5 added a commit to rehevkor5/exec-maven-plugin that referenced this issue Aug 14, 2016
- New "provided" value for classpathScope includes both runtime and
  provided dependencies
- Closes mojohaus#60
rehevkor5 added a commit to rehevkor5/exec-maven-plugin that referenced this issue Aug 15, 2016
- New "provided" value for classpathScope includes both runtime and
  provided dependencies
- Closes mojohaus#60
@rehevkor5
Copy link
Contributor Author

@khmarbaise #61 created to resolve this.

@khmarbaise khmarbaise added this to the 1.6.0 milestone Aug 31, 2016
@rfscholte rfscholte removed this from the 1.6.0 milestone Mar 2, 2017
@bondolo
Copy link

bondolo commented Feb 6, 2018

@khmarbaise wrote:

I know that the provided scope is not available on the classpath cause it's defined provided which means it is provided by the runtime environment.

For exec:java there isn't usually anywhere else that the provided dependencies could come from unless they actually part of the standard java libraries. ie. built-in classes. The request in #61 is to make the provided depdendencies available in the runtime.

While the "provided" dependencies might be expected to be available in normal/exepcted execution circumstances it seems reasonable for exec:java to act as "provider" of these dependencies if it is acting as the execution container. Since exec:java is the execution container and the "provided" and "optional" dependencies won't otherwise be available it might even be argued that including them should be the default behaviour of exec:java.

@rehevkor5
Copy link
Contributor Author

rehevkor5 commented Feb 11, 2018

@bondolo Exactly! For local development purposes it's often useful to be able to run an app and use Maven to supply the "provided" dependencies rather than using the full deployment environment.

@lbreuss
Copy link

lbreuss commented May 26, 2020

@rehevkor5 What is the status of your merge request? Has it been cancelled or ignored?

This feature would be very welcome. My software references org.slf4j:slf4j-api:provided, and some :runtime dependencies down the road... Currently, I cannot run the application, as either scope "compile" or scope "runtime" will miss one or the other dependency...

rehevkor5 added a commit to rehevkor5/exec-maven-plugin that referenced this issue May 26, 2020
- New "provided" value for classpathScope includes both runtime and
  provided dependencies
- Closes mojohaus#60
@rehevkor5
Copy link
Contributor Author

@lbreuss The PR #61 has been ignored so far. At some point merge conflicts evolved from changes in master branch. I have just resolved those. If the builds succeed, the PR will again be ready to merge.

@bondolo
Copy link

bondolo commented May 27, 2020

I pinged @rfscholte and @khmarbaise on twitter. It appears this issue is at an impasse unless @olamy is able to approve. This project seems to need new/additional maintainers.

@asbachb
Copy link

asbachb commented Apr 19, 2022

I know that the provided scope is not available on the classpath cause it's defined provided which means it is provided by the runtime environment. That was the reason that i said you could provide a patch which solves this problem ?

I guess there are use cases where you could consider exec-maven-plugin as the runtime environment.

@inzucchi
Copy link

inzucchi commented Feb 25, 2024

Hi @rehevkor5, @olamy, @khmarbaise , @rfscholte, Any chance this can get deployed? I'm also having the same issues.

As a workaround, I tried using the additionalClasspathElements parameter with the required classpath, along with using the parameter classpathScope="runtime", but the additionalClasspathElements parameter does not seem to be used. From looking at the code, the value of this parameter seems to be ignored, even though it is documented as a valid optional parameter of the exec:java goal of the exec-maven-plugin on this page: https://www.mojohaus.org/exec-maven-plugin/java-mojo.html#additionalClasspathElements . Is this a known bug ?

@rehevkor5
Copy link
Contributor Author

I don't know, it seems like this repo is abandoned, since it's been 8 years since I made the PR. I guess I/we/someone could publish a fork of this plugin, as a way to make it available.

@slawekjaranowski
Copy link
Member

@rehevkor5 thanks for your efforts, as you see a project is not abandoned, I did a release two weeks ago ...

But you are right there are many open issues and PR, simply there are not many maintainers, so sorry for missed this one.

Nevermind if you rebase your PR again I can try to merge.

rehevkor5 added a commit to rehevkor5/exec-maven-plugin that referenced this issue Mar 10, 2024
- New "provided" value for classpathScope includes both runtime and
  provided dependencies
- Closes mojohaus#60
@rehevkor5
Copy link
Contributor Author

@slawekjaranowski Oh great, thanks! I rebased it & reran tests.

The only problem was unrelated: the method test_exec_receives_all_parameters doesn't work for me... possibly because on Windows mkdir is a builtin rather than an actual executable. But everything else succeeded.

rehevkor5 added a commit to rehevkor5/exec-maven-plugin that referenced this issue Mar 10, 2024
- New "provided" value for classpathScope includes both runtime and
  provided dependencies
- Closes mojohaus#60
slawekjaranowski pushed a commit that referenced this issue Mar 13, 2024
- New "provided" value for classpathScope includes both runtime and
  provided dependencies
- Closes #60
@inzucchi
Copy link

inzucchi commented Mar 13, 2024

Oh wow, thanks SO much @rehevkor5 and @slawekjaranowski for all your help on this! It's amazing you could still work on this, even 8 years later! :-) Will this be part of a planned release? Wondering how we can download it via maven.

Also, I ran into another issue for this plugin, 51, which was fixed, but then was reverted, which I ran into when I was attempting to use the additionalClasspathElements parameter as a workaround. Any chance on getting this fixed? I will post in the related issue, but just thought I would post this here too, as I mentioned it in my previous comment above, also.

@slawekjaranowski
Copy link
Member

slawekjaranowski commented Mar 13, 2024

@inzucchi I did a release a 3 waks ago ... 😄 I can do next release
but I would like to wait a few weeks unless we have a critical bugs - I would like wait for feedback on the last release.

I see there are a many open issues, some are very old and should be checked with the latest version.
So any help from contributors will be appreciated.

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.

8 participants