Coder Social home page Coder Social logo

mojo-executor / mojo-executor Goto Github PK

View Code? Open in Web Editor NEW
194.0 194.0 48.0 312 KB

The Mojo Executor provides a way to to execute other Mojos (plugins) within a Maven plugin, allowing you to easily create Maven plugins that are composed of other plugins.

Home Page: http://mojo-executor.github.io/mojo-executor/

License: Other

Groovy 11.51% Java 88.49%
java maven

mojo-executor's Introduction

Build Status Maven Central

The Mojo Executor provides a way to execute other Mojos (plugins) within a Maven plugin, allowing you to easily create Maven plugins that are composed of other plugins.

Note from the Maintainers

Tim Moore

I'm no longer maintaining this project actively, as I no longer use it (and have moved away from Maven and Java entirely). It's a simple library that does its job, and a lot of people are using it effectively in its current state.

I am happy to continue reviewing and merging pull requests, and releasing new versions to Maven Central. Most of the contributions so far have come from other people, and I'm very grateful to the people that have helped to improve Mojo Executor.

I do want to make it clear, however, that I won't be personally working on any bug reports or feature requests that come through the issue tracker without a pull request. I hope the community of Mojo Executor users will help answer questions and troubleshoot problems reported there.

If anyone in the community would like to take over as full-time maintainer, let's talk! Email me at [email protected] and we can set up a Skype call or Google Hangout to discuss it in detail.

Cheers, — Tim

Nick Cross

While I am no longer actively using this plugin I am happy to review, assist with contributions, merge PRs and release new versions. I have released the last few versions rolling up all the various fixes and improvements.

Cheers, — Nick

News

  • 10 Mar 2022 — Mojo Executor 2.4.0 released
  • 10 Feb 2022 — Mojo Executor 2.3.3 released with updated dependencies
  • 1 Sep 2021 — Mojo Executor 2.3.2 released (by Nick Cross) with various bug fixes and minor improvements
  • 21 Nov 2019 — Mojo Executor 2.3.1 released (by Nick Cross) with various bug fixes and minor improvements
  • 4 May 2017 — Mojo Executor 2.3.0 released (by Nick Cross) with various bug fixes and minor improvements.
  • 27 Mar 2014 — Mojo Executor 1.5.2 released with support for Maven 2 through 3.1.
  • 12 Feb 2014 — I'm looking for a new maintainer for this project. If you're interested, please get in touch!
  • 26 Nov 2013 — Mojo Executor 2.2.0 released with support for attributes in plugin configuration.
  • 25 Aug 2013 — Mojo Executor 2.1.0 released with support for Maven 3.1.

Downloads

You can download the JARs, source, and Javadocs from Maven central:

https://search.maven.org/search?q=g:org.twdata.maven

Example Usage

MojoExecutor defines a number of builder methods that are intended to be imported statically:

import static org.twdata.maven.mojoexecutor.MojoExecutor.*

This is how you would execute the "copy-dependencies" goal of the Maven Dependency Plugin programmatically:

executeMojo(
    plugin(
        groupId("org.apache.maven.plugins"),
        artifactId("maven-dependency-plugin"),
        version("2.0")
    ),
    goal("copy-dependencies"),
    configuration(
        element(name("outputDirectory"), "${project.build.directory}/foo")
    ),
    executionEnvironment(
        mavenProject,
        mavenSession,
        pluginManager
    )
);

The project, session, and pluginManager variables should be injected via the normal Mojo injection:

@Component
private MavenProject mavenProject;

@Component
private MavenSession mavenSession;

@Component
private BuildPluginManager pluginManager;

An alternative form for the executionEnvironment, ignoring the optional MavenProject, is:

    executionEnvironment(
        mavenSession,
        pluginManager
    )

You might need to add other annotations to your Mojo class, depending on the needs of your plugin. Annotations declared by Mojos that you execute are not automatically inherited by your enclosing Mojo.

For example, if you are using the maven-dependency-plugin, as in this example, you will need to add @requiresDependencyResolution <scope> to your class annotations to ensure that Maven resolves the project dependencies before invoking your plugin.

See the Mojo API Specification for details on available annotations. Look at the included example plugin for an example of use.

Maven Dependency

Add this to your pom.xml:

<dependencies>
    <dependency>
        <groupId>org.twdata.maven</groupId>
        <artifactId>mojo-executor</artifactId>
        <version>2.4.0</version>
    </dependency>
</dependencies>

Maven Compatibility

  • 2.4.x — Requires Maven 3.3.1 or later
  • 2.1.x/2.2.x — Support Maven 3.x
  • 2.0.x — Supports Maven 3.0.x only
  • 1.5.x — Supports both Maven 2.x and Maven 3.x
  • 1.0.1 — Supports Maven 2.x only

License

Copyright 2008-2013 Don Brown

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

Mojo Executor was originally created by Don Brown ([email protected]).

It is currently maintained by Tim Moore ([email protected]) and Nick Cross ([email protected])

Thanks to the following contributors, who have provided patches and other assistance:

mojo-executor's People

Contributors

andrei-pozolotin avatar cowwoc avatar dependabot[bot] avatar docdoc avatar gcacace avatar kwin avatar marcelstoer avatar matthewmccullough avatar olamy avatar rnc avatar rombert avatar timmoore avatar tobiashochguertel avatar wb14123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mojo-executor's Issues

object creation error Plugin

call java Plugin pluginDependency = plugin("org.apache.maven.plugins", "maven-dependency-plugin"); does not return a full plug according pluginManagement project.
works only explicit version: java Plugin pluginDependency = plugin("org.apache.maven.plugins", "maven-dependency-plugin", "2.8");

pluginManagement:

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
        </plugin>
    </plugins>
</pluginManagement>

Convert the build to use Maven Wrapper

well ideally you could stop using this setup maven :) and add a step to setup mvnw such mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.1.0:wrapper "-Dmaven=${{ matrix.maven }}"

Originally posted by @olamy in #82 (comment)

executing dependency plugin list goal is not working

Hi

I was trying to execute the dependency plugin through the mojo executor. The weird thing is "tree" goal is working and generating the file with the dependency tree information. But when i change the goal to "list" or "copy-dependencies", the execution goes through fine but no action happens. There is no error or warning. when i enable debug messages, i see that the execution of plugin stops during configuration.

Regards
Kamal

Move to an organization?

GitHub offers more flexible access control for repositories owned by organizations vs. individual accounts. See Permission levels for a user account repository.

I've thought about transferring this project to an organization. There's no reason to keep it associated with my personal account, since I am neither the original creator nor the most active maintainer (or even a user at this point).

Is there an existing organization that would make sense as a home for the project, or should I create a dedicated one?

I'm opening this for public discussion for 14 days.

@rnc: since you have done all of the recent maintenance, I won't make any changes unless you agree.

I'd be happy to hear from any other users, former maintainers, or other interested people as well. If there aren't any objections or suitable existing organizations suggested by 20 Sep 2021, I'll plan to transfer the repository to the https://github.com/mojo-executor organization, which I have just reserved. If we do find a more suitable organization, I'll delete that one.

Example doesn't seem to work?

I'm trying to use this handy looking tool (to build a Maven packaging tool for JavaFX).

I'd actually like to do exactly what your example does and call the dependency plugin to copy dependencies (actually unpack them, but it's much the same).

I've used the example on the wiki verbatim (https://github.com/TimMoore/mojo-executor), although I did have to change the 'PluginManager' to a 'BuildPluginManager' to make it compile.

When it runs it is definitely finding and I think calling the dependency plugin (if I change any of the config settings it fails with an appropriate error), but it does not copy any of my dependencies at all. It basically succeeds but nothing happened during the execution - like it thinks the project has no dependencies.

If I manually configure the dependency plugin in the XML (i.e. calling it the normal maven way, not using this project) using the exact same configuration settings it copies the dependencies fine and prints out to the log that it is doing that. i.e. everything works fine.

Do you know if I am missing anything here? Should your example just work, or is there something more that needs to be done?

SurefireBooterForkException when running surefire plugin

I am getting an exception when I try to execute surefire plugin using mojo-executor. Code to run the plugin is:

        getLog().info("Running unit tests");
        Plugin plugin = MojoExecutor.plugin("org.apache.maven.plugins","maven-surefire-plugin", "2.20.1");
        String goal = MojoExecutor.goal("test");
        Xpp3Dom configuration = MojoExecutor.configuration(
                new Element("argLine", "-Xmx1024m ${surefireArgLine}"),
                new Element("printSummary", "false"),
                new Element("excludes",new Element("exclude","**/contract/**")));
        ExecutionEnvironment env = MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager);
        executeMojo(plugin, goal, configuration, env);
        getLog().info("Tests were run");

And following is the exception I get. Any idea to make it right?

[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] org/springframework/test/web/servlet/RequestBuilder
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] org/springframework/test/web/servlet/RequestBuilder
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:673)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:535)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:280)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1124)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:954)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:832)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR]         at org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo(MojoExecutor.java:119)
[ERROR]         at org.myorg.CodeCoverage.unitTestExecution(CodeCoverage.java:89)
[ERROR]         at org.myorg.CodeCoverage.execute(CodeCoverage.java:64)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Plugin to wrap non-threadsafe plugins

I'm looking for a plugin that could be used to wrap another plugin that is not threadsafe, could this project be enhanced to support this use-case? I think just a global mutex would need to be added around the non-threadsafe plugin. The goal being to force the Maven reactor to use the non-threadsafe plugin by one thread at a time even with builds using multiple threads.

Trying to mark a directory as source

I am trying to execute this:

executeMojo(
                plugin(
                        groupId("org.codehaus.mojo"),
                        artifactId("build-helper-maven-plugin"),
                        version("3.3.0")
                ),
                goal("add-source"),
                configuration(
                        element(name("sources"),
                                element(name("source"), getOutputDirectory().getPath())
                        )
                ),
                executionEnvironment(
                        project,
                        mavenSession,
                        pluginManager
                )
        );

But the folder is never detected by the IDE as generated source.

If I execute the normal maven script it works:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>my-id</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.basedir}/src/main/resources/processes/generated</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Any idea why?

I'm using IntelliJ Ultimate latest version.
I tried using Eclipse latest version, same problem.

I also tried doing this (the source code for the add-source from apache repos):

project.addCompileSourceRoot(getOutputDirectory().getPath());
        if (getLog().isInfoEnabled()) {
            getLog().info("Source directory: " + getOutputDirectory().getPath() + " added.");
        }

And it does not work. If I use my own maven plugin, the directory change is never detected.

My Stack Overflow post:
https://stackoverflow.com/questions/71214163/unable-to-set-directory-as-resource-source-in-maven-custom-plugin

Unable to execute maven-antrun-plugin due to xml parsing errors

The values of the "target" attribute in the antrun plugin is xml, which causes the xml to be escaped before being passed to the antrun plugin:

executeMojo(
    plugin(
        groupId("org.apache.maven.plugins"), artifactId("maven-antrun-plugin"), version("1.7")
    ),
    goal("run"),
    configuration(
        element(name("target"), 
                "<delete dir=\"target/resources\" />" +
                "<unzip src=\"${com.foo:shared-resources:war}\" dest=\"target/resources\" overwrite=\"true\" >" +
                    "<patternset>" + 
                        "<include name=\"docroot/**\"/>" + 
                    "</patternset>" +
                "</unzip>"
                )
    ),
    executionEnvironment(project, session, pluginManager)
);
[ERROR] Failed to execute goal com.foo.bar:ivmodules-maven-plugin:0.0.1-SNAPSHOT:run (default-cli) on project ivplugin: Unable to execute mojo: An AntBuildException has occured: Unexpected text "<"
[ERROR] around Ant part ...<target name="main">&lt;delete dir=&quot;target/resources&quot; /&gt;&lt;unzip src=&quot;${com.foo:shared-resources:war}&quot; dest=&quot;target/resources&quot; overwrite=&quot;true&quot; &gt;&lt;patternset&gt;&lt;include name=&quot;docroot/**&quot;/&gt;&lt;/patternset&gt;&lt;/unzip&gt;</target>... @ 3:25 in C:\dev\ivplugin\target\antrun\build-main.xml

Then I tried to get creative and I tried to use the MojoExecutor's syntax for the plugin configuration xml creation:

executeMojo(
    plugin(
        groupId("org.apache.maven.plugins"), artifactId("maven-antrun-plugin"), version("1.7")
    ),
    goal("run"),
    configuration(
        element(name("target"), 
            element(name("unzip src=\"${com.foo:shared-resources:war}\" dest=\"target/resources\" overwrite=\"true\""),
                element(name("patternset"),
                    element("include name=\"docroot/**\"/>","")
                )
            )
        )
    ),
    executionEnvironment(project, session, pluginManager)
);
[ERROR] Failed to execute goal com.foo.bar:ivmodules-maven-plugin:0.0.1-SNAPSHOT:run (default-cli) on project ivplugin: Unable to execute mojo: An Ant BuildException has occured: The end-tag for element type "delete" must end with a '>' delimiter.
[ERROR] around Ant part ...<delete dir="target/resources"></delete dir="target/resources">... @ 4:43 in C:\dev\ivplugin\target\antrun\build-main.xml

Would it be possible to send raw text as input to a configuration attribute?

"compile" scoped dependency on slf4j-simple is a bad idea

Now you depend on org.slf4j:slf4j-simple in "compile" scope, which makes my Maven to put it to classpath and conflict with my own version of slf4j bindings, which are of higher versions. I suggest you move yours to "test" scope.

Here just add <scope>test</scope>

Test with Maven 4.0.0 prereleases

In #82, I tried adding Maven 4.0.0-alpha-4 to the build matrix, but it resulted in a build failure.

Error: Failed to execute goal org.apache.maven.plugins:maven-invoker-plugin:3.2.2:install (default) on project mojo-executor-maven-plugin: Failed to install project dependencies: MavenProject: org.twdata.maven:mojo-executor-maven-plugin:2.4.1-SNAPSHOT @ /home/runner/work/mojo-executor/mojo-executor/mojo-executor-maven-plugin/pom.xml: Failed to install project artifacts: MavenProject: org.twdata.maven:mojo-executor:2.4.1-SNAPSHOT @ /home/runner/work/mojo-executor/mojo-executor/mojo-executor/pom.xml: Failed to install artifact: org.twdata.maven:mojo-executor:pom:consumer:2.4.1-SNAPSHOT: transformed artifact file cannot be set -> [Help 1]

Issue executing mvn versions:use-next-versions

When I execute the following Mojo it has no effect.
When run via mvn versions:use-next-versions the poms are changed as expected.

        executeMojo(
                plugin(
                        groupId("org.codehaus.mojo"),
                        artifactId("versions-maven-plugin"),
                        version("2.1")
                ),
                goal("use-next-versions"),
                configuration(
                        element(name("generateBackupPoms"), "false"),
                        element(name("allowSnapshots"), "false")
                ),
                executionEnvironment(
                        rootProject,
                        session,
                        pluginManager
                )
        );

Update dependencies

Hi,

Version 2.3.0 pulls an outdated version of org.sonatype.sisu which breaks compilation on Java9+. Please update your transitive dependency to:

<dependency>
	<groupId>org.sonatype.sisu</groupId>
	<artifactId>sisu-inject-plexus</artifactId>
	<version>2.6.0</version>
</dependency>

Executing mojo in other directory problem

I execute maven-release-plugin in my mojo. Before execute I checkout latest module version to directory. I want release this module, but execute mojo run for main module. What to do?

Allow building/testing with Maven 2.1.0

This library is meant to be compatible with Maven 2.1.0, but due to requirements for deploying to Maven Central, currently contains an enforcer rule that requires 2.2.1 or later.

It would be nice to be able to at least compile and test with 2.1.0 using an alternate profile, with deployment disabled.

RFC: change the group ID and package from org.twdata.maven to io.github.mojo-executor

The twdata.org domain isn't controlled by me, or anyone else still involved with the project in any way. It actually appears that the registration has lapsed.

Changing the group ID and package is not a backward compatible change (and should therefore change the major version number) but the old and new versions could coexist compatibly in the same classpath.

There's no urgent need to do this, but it might make it easier to find the project information, as well as making it easier to manage permissions for contributors in the future.

https://central.sonatype.org/publish/requirements/coordinates/

I'm opening this issue for comments from anyone interested, for or against. I'll give it some time before making any changes.

Reload Maven project

Is there a way to reload/refresh the MavenProject, MavenSession and BuildPluginManager after a executeMojo run.

My issue is as follows:

My poms are at version 1.0-SNAPSHOT
If My Mojo then runs the following executeMojo to set the pom versions to 1.0

    executeMojo(
            plugin(
                    groupId("org.codehaus.mojo"),
                    artifactId("versions-maven-plugin"),
                    version("2.1")
            ),
            goal("set"),
            configuration(
                    element(name("generateBackupPoms"), "false"),
                    element(name("newVersion"), "1.0")
            ),
            executionEnvironment(
                    rootProject,
                    session,
                    pluginManager
            )
    );

My Mojo then runs deploy like below. However what gets deployed is 1.0-SNAPSHOT (not 1.0)

    executeMojo(
            plugin(
                    groupId("org.apache.maven.plugins"),
                    artifactId("maven-deploy-plugin"),
                    version("2.8.1")
            ),
            goal("deploy"),
            configuration(
                    element(name("skip"), "false"),
                    element(name("retryFailedDeploymentCount"), "1")
            ),
            executionEnvironment(
                    rootProject,
                    session,
                    pluginManager
            )
    );

pom.xml compiler plugin not configured

For me, it seems that the pom.xml files are erroneous. The project does not compile with Apache Maven 3.6.1 because it does not support Java version 1.5 anymore. On the other hand, the parent pom seemingly defines the source and the target to 1.8. But it does not.

What the parent pom does it that it configures a plugin, specifically the

          <groupId>org.apache.maven</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>

plugin, which does not exist. The groupId is missing the .plugins from the end. It does not cause a compilation problem with Maven 2, because this is just plugin management and as such, it is only declaration. It would cause a problem when the plugin is to be used. But it is not. It is not in the build/plugin area in the parent pom and it is not in the children's poms.

This also explains why there is a //TODO in the code to upgrade exception handling to Java 7 style. It was not compiling because the actual version was Java 1.5

I did these changes and I could compile the project with the Maven version mentioned above. It probably works, I have not checked.

Anyway to pass --quiet option

When running Mojo-Executor I'd like it to be silent. Only print Warning and Errors thrown by the goal being run

mvn has a --quiet option anyway to use that with Mojo-Executor?

Repo Secret

@TimMoore Can you create two repository secrets (SONATYPE_PASSWORD) and (SONATYPE_USERNAME) in order for snapshots to deploy correctly please? (or you could give me access and I'll do it).

Update 'save-state' to Environment Files

I noticed this warning in the build logs, in the "Cache local Maven repository" step:

Warning: The `save-state` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Cache not found for input keys: Linux-maven-3127b302e3ca07ef1885b75348fdb0d5a20ffe0cd0e2a5637e22731dcf657b05, Linux-maven-

According to the linked explanation the save-state command will be disabled on 31st May 2023. I'm guessing this only requires updating to a newer version of the action, but I have not investigated yet.

New release?

Hi,
As the latest release is almost 2 years old, I was wondering if 2.3.2 release was planned?
Biggest unreleased fix (as far as I see) is in PR #52, and it might be a blocker for our use case.

Thanks in advance!
cc: @TimMoore

Running Mojos with dependencies

Hi,

I want to run a goal exactly like if it was run from maven. Unfortunately, this does not seem to work with testCompile. The dependency to testCompile is set as follows:

               <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
        </dependency>

And the code for the execution is the following:

                Plugin p = new Plugin();
        p.setGroupId("org.apache.maven.plugins");
        p.setArtifactId("maven-compiler-plugin");
        p.setVersion("3.1");
        try {
            MojoExecutor.executeMojo(p, "testCompile", MojoExecutor
                    .configuration(), MojoExecutor
                    .executionEnvironment(project, mavenSession, pluginManager));
        } catch (MojoExecutionException e) {
            // TODO Automatisch generierter Erfassungsblock
            e.printStackTrace();
        }

with project, mavenSession and pluginManager injected as usual. Unfortunately, I get errors everywhere because of the not-found dependencys.

The same is happening, if I try to run build-classpath - I just get now librarys, while I get the librarys normally when running in maven. Is this a mistake of me, or is it maybe possible to add a functionality that transports the dependencies to the child-mojo-runs?

King Regards
DaGeRe

mojo-executor 2.2.0 with maven 3.3.9

Hi,

when we used mojo-executor 2.2.0 with maven 3.3.9 in one of our plugin and building app some app using this plugin getting below error:

Unable to execute mojo: java.lang.reflect.InvocationTargetException: NullPointerException -> [Help 1]

Could you please update on this

Thanks,
Hidayath.

Issue passing too many parameters in the configuration

Hi,

I am using your plugin to execute the maven-android-plugin with the following code -

private void executeAPKBuilder(){
try {
executeMojo(
plugin(
groupId("com.jayway.maven.plugins.android.generation2"),
artifactId("android-maven-plugin"),
version("3.8.1")
),
goal("apk"),
getConfiguration(),
executionEnvironment(
project,
session,
pluginManager
)
);
} catch (MojoExecutionException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}

private Xpp3Dom getConfiguration(){
    project.getBuildPlugins().iterator();
    for (Iterator iterator = project.getBuildPlugins().iterator(); iterator.hasNext();) {
        Plugin plugin = (Plugin) iterator.next();
        if("android-maven-plugin".equalsIgnoreCase(plugin.getArtifactId())) {
            return (Xpp3Dom)plugin.getConfiguration();
        }
    }
    return null;
}

However, in the pom, the configuration section of the android-maven-plugin contains elements that are not used in this particular goal. As such, I am receiving a number of errors in a format similar to

Caused by: org.apache.maven.plugin.PluginConfigurationException: Unable to parse configuration of mojo com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.1:apk for parameter lint: Cannot find 'lint' in class com.jayway.maven.plugins.android.phase09package.ApkMojo

Is there a property that can be set to so that this scenario is silently consumed?

Thanks in advance,
Gary

Support usage in mojos that do not require a MavenProject

Sometimes we need to write mojo goals that do not require a MavenProject. The install-file goal form the maven-install-plugin is a good example.

For now we cannot use mojo-executor in such goals because ExecutionEnvironment requires a non-null MavenProject.

I'm not sure it's even feasible but would be very nice.

mojo-executor 1.5 with maven 3.3.9

Hi,

we are using mojo-executor 1.5 with maven 3.3.9 in one of our plugin
when we used that plugin in application getting below mentioned error

Failed to execute goal com.iggroup.wt.fe.maven:wt-fe-maven-plugin:3.26.0-SNAPSHOT:build-to-webapp (default) on project wt-payments-ui-weblib-desktop: Execution default of goal com.iggroup.wt.fe.maven:wt-fe-maven-plugin:3.26.0-SNAPSHOT:build-to-webapp failed: An API incompatibility was encountered while executing com.iggroup.wt.fe.maven:wt-fe-maven-plugin:3.26.0-SNAPSHOT:build-to-webapp: java.lang.NoSuchMethodError: org.apache.maven.execution.MavenSession.getRepositorySession()Lorg/sonatype/aether/RepositorySystemSession;

NOTE: we are using BuildPluginManager so that mojo-executor will use ExecutionEnvironmentM3.

Could you please update on this issue?

Thanks,
Hidayath.

Document static imports in README

This plugin is great and worked like a charm once I discovered it.

However, it took me a while to figure out which class the static imports were in, as the README doesn't say. I ended up looking at test cases on GitHub, which isn't ideal...

Please add import static org.twdata.maven.mojoexecutor.MojoExecutor.* to the main example in the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.