You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Alex <ak...@yahoo.gr> on 2018/05/18 14:37:28 UTC

Problem with exec-maven-plugin

Hello all,

I have a problem running exec-maven-plugin in a multi-module project
_without_ installing snapshots to my local repository. What happens is that
Maven seems to require that dependencies are "resolved" during the
"generate-sources" phase so if I run "mvn generate-sources" it complains
about previous modules NOT being on the classpath (even though they are not
needed for source generation). Ironically, running "mvn compile" has no
issue as it uses target/classes from previous modules. A simple project to
replicate:

parent-prj
parent-prj/sub-prj
parent-prj/gen-src-prj <-- depends on 'sub-prj', has exec-maven plugin

The POMs:

--------

<?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>mygrp</groupId>
    <artifactId>parent-prj</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <packaging>pom</packaging>

    <modules>
        <module>sub-prj</module>
       <module>gen-src-prj</module>
    </modules>
</project

--------

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>mygrp</groupId>
        <artifactId>parent-prj</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>sub-prj</artifactId>
</project>

--------

<?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>

    <parent>
        <groupId>mygrp</groupId>
        <artifactId>parent-prj</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>gen-src-prj</artifactId>

    <dependencies>
        <dependency>
            <groupId>mygrp</groupId>
            <artifactId>sub-prj</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                   
<includeProjectDependencies>false</includeProjectDependencies>
                   
<includePluginDependencies>true</includePluginDependencies>
                    <mainClass>uk.co.real_logic.sbe.SbeTool</mainClass>
                    <systemProperties>
                        <systemProperty>
                            <key>sbe.output.dir</key>
                           
<value>${project.build.directory}/generated-sources/java</value>
                        </systemProperty>
                        <systemProperty>
                            <key>sbe.validation.warnings.fatal</key>
                            <value>true</value>
                        </systemProperty>
                    </systemProperties>
                    <arguments>
                       
<argument>${project.build.resources[0].directory}/Examples.xml</argument>
                    </arguments>
                   
<workingDirectory>${project.build.directory}/generated-sources/java</workingDirectory>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>uk.co.real-logic</groupId>
                        <artifactId>sbe-tool</artifactId>
                        <version>1.7.10</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

Notice that I use
"<includeProjectDependencies>false</includeProjectDependencies>" in an
attempt to tell Maven that there is no need to actually have project
dependencies actually available. Is there a way to run "mvn
generate-sources" with this structure and have it invoke exec-maven-plugin
without compiling anything?




--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with exec-maven-plugin

Posted by Alex <ak...@yahoo.gr>.
In the interest of providing full reference in the list, I have come up with
a workaround to achieve what I want: I list the dependencies in a profile
that is active by default, then use another profile to run generate-sources
with no dependencies active, like follows:

Added in parent-prj/gen-src-prj/pom.xml (and obviously remove existing
dependencies section)

<profiles>
    <profile>
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>mygrp</groupId>
                <artifactId>sub-prj</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </profile>

    <profile>
        <id>excludeDependency</id>
        <dependencies>
        </dependencies>
    </profile>
</profiles>

To generate sources with above, use: mvn -PexcludeDependency
generate-sources

Also filed a bug against the plugin at:
https://github.com/mojohaus/exec-maven-plugin/issues/106




--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with exec-maven-plugin

Posted by Alex <ak...@yahoo.gr>.
Hi Francois,

Someone on SO has explained that this is related to bug
https://issues.apache.org/jira/browse/MNG-3283

The maven-exec-plugin has "requiresDependencyResolution =
ResolutionScope.TEST"

You can see that annotation here: 
https://github.com/mojohaus/exec-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java

So basically, even though it runs early in the lifecycle phase, it dies
because it expects output to be ready for all dependencies. The
"includeProjectDependencies" setting (which I assumed would change this
behaviour) thus becomes irrelevant: it simply means that the resolved
dependencies will not be in the execution classpath, but Maven still expects
them to be available.

The output is simple:


"mvn compile" output:
----------------------------
[INFO] Scanning for projects...
[INFO]
------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] parent-prj                                                        
[pom]
[INFO] sub-prj                                                           
[jar]
[INFO] gen-src-prj                                                       
[jar]
[INFO] 
[INFO] --------------------------< mygrp:parent-prj
>--------------------------
[INFO] Building parent-prj 1.0.0-SNAPSHOT                                
[1/3]
[INFO] --------------------------------[ pom
]---------------------------------
[INFO] 
[INFO] ---------------------------< mygrp:sub-prj
>----------------------------
[INFO] Building sub-prj 1.0.0-SNAPSHOT                                   
[2/3]
[INFO] --------------------------------[ jar
]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @
sub-prj ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory
/Users/karypid/d/wc/parent-prj/sub-prj/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ sub-prj ---
[INFO] No sources to compile
[INFO] 
[INFO] -------------------------< mygrp:gen-src-prj
>--------------------------
[INFO] Building gen-src-prj 1.0.0-SNAPSHOT                               
[3/3]
[INFO] --------------------------------[ jar
]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:java (default) @ gen-src-prj ---
[Fatal Error] :1:1: Premature end of file.
[WARNING] 
org.xml.sax.SAXParseException: Premature end of file.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse
(DOMParser.java:257)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse
(DocumentBuilderImpl.java:339)
    at javax.xml.parsers.DocumentBuilder.parse (DocumentBuilder.java:121)


ABOVE IS CORRECT BEHAVIOUR: the plugin is executed but fails because it is
missing the "Examples.xml" file which I do not have in this example. Now
contrast this to the output below which exhibits the incorrect/unexpected
behaviour:

"mvn generate-sources" output:
----------------------------
[INFO] Scanning for projects...
[INFO]
------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] parent-prj                                                        
[pom]
[INFO] sub-prj                                                           
[jar]
[INFO] gen-src-prj                                                       
[jar]
[INFO] 
[INFO] --------------------------< mygrp:parent-prj
>--------------------------
[INFO] Building parent-prj 1.0.0-SNAPSHOT                                
[1/3]
[INFO] --------------------------------[ pom
]---------------------------------
[INFO] 
[INFO] ---------------------------< mygrp:sub-prj
>----------------------------
[INFO] Building sub-prj 1.0.0-SNAPSHOT                                   
[2/3]
[INFO] --------------------------------[ jar
]---------------------------------
[INFO] 
[INFO] -------------------------< mygrp:gen-src-prj
>--------------------------
[INFO] Building gen-src-prj 1.0.0-SNAPSHOT                               
[3/3]
[INFO] --------------------------------[ jar
]---------------------------------
[INFO]
------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] parent-prj 1.0.0-SNAPSHOT .......................... SUCCESS [  0.004
s]
[INFO] sub-prj ............................................ SUCCESS [  0.002
s]
[INFO] gen-src-prj 1.0.0-SNAPSHOT ......................... FAILURE [  0.090
s]
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 0.203 s
[INFO] Finished at: 2018-05-20T09:02:29+01:00
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal on project gen-src-prj: Could not resolve
dependencies for project mygrp:gen-src-prj:jar:1.0.0-SNAPSHOT: Could not
find artifact mygrp:sub-prj:jar:1.0.0-SNAPSHOT -> [Help 1]

As you can see Maven refuses to even attempt to invoke exec-maven-plugin. It
was instructed by "requiresDependencyResolution = ResolutionScope.TEST" to
resolve dependencies for TEST scope and since that cannot be done (I have
nothing in my local repository, nor was any output created as we were not
running the compile goal) it has no way of doing that.

Basically I think it is more a problem of exec-maven-plugin code: it clearly
asks Maven to behave like this. It should remove the annotation for
requiresDependencyResolution and programmatically check for the presence of
output in its code when "includeProjectDependencies" is set to true in its
configuration.

I was going to create an account to watch this bug, but then I noticed that
it's been around 10 (!) years and has 26 votes and 37 watchers, so I doubt
it will ever be fixed.

It's a pity because I fully subscribe to the philosophy mentioned in this
bug:
https://issues.apache.org/jira/browse/MNG-3283?focusedCommentId=14415669&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14415669

A lot of people I've worked with that have not contact with maven other than
working on a project that uses it, complain about weird classpath issues.
When I look into them, it always ends up being a user of IntelliJ that has
not run "mvn install" for project A and cannot see his change in project B.
I encourage people to NEVER run "mvn install" to avoid such issues, but this
bug makes it impossible... (usually the problem happens in IntelliJ because
m2eclipse prioritises workspace project by default; if you import A and B
into your workspace Eclipse links against each other).






--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with exec-maven-plugin

Posted by Francois MAROT <fr...@gmail.com>.
Hi Alex,

maybe you could paste here the output logs of the failing execution. I'd
like them to be sure I understand the problem.
Cheers

Francois



--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org