I'm using the GMaven plugin to evoke a Groovy script I have defined in my Maven project.
So I have something like:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>Running Unicorn</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scriptPath>
<path>${project.basedir}/src/main/script</path>
</scriptPath>
<source>
import Helper
new Helper().doSomething()
</source>
</configuration>
</execution>
</executions>
</plugin>
When it goes to execute the source section of this plugin I get the following error:
[ERROR] Failed to execute goal
org.codehaus.gmaven:gmaven-plugin:1.5:execute (Running Groovy
Execution) on project test-project: startup failed,
script1540154364455.groovy: 1: unable to resolve class Helper [ERROR]
# line 1, column 1. [ERROR] 1 error
The path to the script directory is correct, I verified that and the ability to execute Groovy by printing out the path to the Groovy script scriptPath.path.
I'm using the documentation located here but to no avail:
https://groovy.github.io/gmaven/groovy-maven-plugin/scriptpath.html
What am I doing wrong here? Any help or pointers would be appreciated
Related
I have been unable to use the checkstyle check goal. I'm getting the following error:
Unable to find configuration file at location:
${project.parent.basedir}/.settings/my_checks.xml: Could not find
resource '${project.parent.basedir}/.settings/my_checks.xml'.
I get this error when I use the command mvn checkstyle:check, but if I run mvn checkstyle:checkstyle this configuration file is found and used as expected.
The plugin configuration is shown below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
...
<properties>
<checkstyle.config.location>${project.parent.basedir}/.settings/my_checks.xml</checkstyle.config.location>
</properties>
Any suggestions? Why would the checkstyle goal work but not the check goal?
Edit: Upon further review I have learned that ${project.parent.basedir} does not resolve when running the check goal. It does resolve when calling the checkstyle goal. Still looking for suggestions / workarounds...
My workaround has been to move away from using the ${project.parent.basedir} variable and to use relative paths. This works in my case because all my modules are parallel directories.
<checkstyle.config.location>../parent/.settings/my_checks.xml</checkstyle.config.location>
I am trying to overwrite the following property in maven using gmaven:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>setproperty</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
pom.properties['main.build.directory']=project.parent.build.directory.absolutePath.replace('\\','/');
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
But I get this error:;
[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.5:execute (setproperty) on project my-project: startup failed, script139276
2592853.groovy: 1: expecting ''', found '<EOF>' # line 1, column 84.
[ERROR] 1 error
What is wrong with the above groovy snippet?
Value of a property which is set using gmavenplus-plugin displays correctly when accessed using the plugin. It will display correctly even if it is accessed using different instances of the same plugin.
Problem arises when value of a property which is already initialized outside the plugin is altered by the plugin and it is accessed outside the plugin. Now the value of the property is not the value as updated by plugin. The updated value is now scoped within the plugin. As a workaround to solve this issue if a property has to be updated by the plugin and is required to be accessed outside the scope of plugin: do not declare or initialize it, in case it needs to be then declare and initialize the property through the plugin.
I agree with #khmarbaise that this is a little weird to do, but if you must...I'm not sure offhand why it isn't working. That plugin isn't really maintained anymore. <shamelessPlug>I think this should work:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>setproperty</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script><![CDATA[project.properties['main.build.directory']=project.parent.build.directory.replace('\\','/')]]></script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>
For more info on this mojo, check out http://groovy.github.io/GMavenPlus/execute-mojo.html.
</shamelessPlug>. However, be aware that I believe this will be scoped within the plugin.
This is part of my pom.xml of my .ear file
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>wls-maven-plugin</artifactId>
<version>12.1.1.0</version>
<configuration>
<adminurl>${adminURL}</adminurl>
<user>${username}</user>
<password>${pswrd}</password>
<upload>true</upload>
<remote>false</remote>
<verbose>true</verbose>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<name>${project.build.finalName}</name>
<targets>${serverName}</targets>
<noExit>true</noExit>
<middlewareHome>${middlewareH}</middlewareHome>
<domainHome>${domainH}</domainHome>
</configuration>
<executions>
<execution>
<id>stopserver</id>
<phase>install</phase>
<goals>
<goal>stop-server</goal>
</goals>
<configuration>
<action>stopserver</action>
<workingDir>${stopScriptDirectory}</workingDir>
<command>stopScript.sh</command>
</configuration>
</execution>
</executions>
</plugin>
I am trying to stop the server by running the stopScript.sh
This is the error I am getting when it is trying to execute the stop-server goal:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.oracle.weblogic:wls-maven-plugin:12.1.1.0:stop-server (stopserver) on project OventusEAR2: Unable to parse configuration of mojo com.oracle.weblogic:wls-maven-plugin:12.1.1.0:stop-server for parameter command: Cannot assign configuration entry 'command' with value 'stopScript.sh' of type java.lang.String to property of type java.lang.String[]
Any ideas?
Though I am not familiar with this particular plugin, however I have seen similar issues before, I guess command parameter is expecting an array instead.
Please try replacing
<command>stopScript.sh</command>
with
<command>
<value>stopScript.sh</value>
</command>
and test again.
Complete Maven newb here, so forgive any abused terminology, etc.
I've built a custom plugin in Maven 3 (one that defines goals for git rebase). I'm able to:
mvn install
No problem. I can then invoke the goal from the command line:
mvn edu.clemson.cs.rsrg:git-plugin:rebase
Everything's golden. I have this lovely git-plugin-XXX.jar file sitting in my target directory.
I'd like to make my custom goals available to another project such that when other members of the dev team pull down that project's source, they get my plugin for free (or at least, after a mvn build).
My understanding is that the purist solution is to set up a maven repo for the group and load my plugin there, but that seems overkill for a single hacky plugin.
Thoughts?
I've played with doing it via three different plugins so far:
addjars-maven-plugin:add-jars
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.4</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/plugins</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Gives me this error during mvn build:
[ERROR] Error resolving version for plugin 'edu.clemson.cs.rsrg:git-plugin' from the repositories [local (/home/hamptos/.m2/repository), central (http://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository
It also causes my later formatting plugin to fail. (Clearly it's read the jar and determined the group name/plugin name, but then it goes and looks for it in my local repo? Of course it's not there--I'm trying to install it.)
build-helper:attach-artifacts
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>install</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${basedir}/plugins/git-plugin-0.1.0a.jar</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Gives me this error during mvn build:
[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) on project RESOLVE: Execution attach-artifacts of goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact failed: For artifact {edu.clemson.cs.rsrg:RESOLVE:12.09.01a:jar}: An attached artifact must have a different ID than its corresponding main artifact.
(RESOLVE:12.09.01a being the main project. Clearly something's gone awry here because the plugin and main project definitely have different artifactIDs. Trying to attach the project on top of itself maybe?)
maven-install-plugin:install-file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>install-git-plugin</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/plugins/git-plugin-0.1.0a.jar</file>
<packaging>jar</packaging>
<groupId>edu.clemson.cs.rsrg</groupId>
<artifactId>git-plugin</artifactId>
<version>0.1.0a</version>
</configuration>
</execution>
</executions>
</plugin>
Seems to work fine until I try to invoke one of the goals like mvn edu.clemson.cs.rsrg:git-plugin:rebase, at which point it gives me this error:
[ERROR] Failed to execute goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase (default-cli) on project RESOLVE: Execution default-cli of goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase failed: Unable to load the mojo 'rebase' (or one of its required components) from the plugin 'edu.clemson.cs.rsrg:git-plugin:0.1.0a': com.google.inject.ProvisionException: Guice provision errors:
[ERROR]
[ERROR] 1) Error in ComponentFactory:ant-mojo
[ERROR] at ClassRealm[plugin>edu.clemson.cs.rsrg:git-plugin:0.1.0a, parent: sun.misc.Launcher$AppClassLoader#e776f7]
[ERROR] while locating org.apache.maven.plugin.Mojo annotated with #com.google.inject.name.Named(value=edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase)
You may think it is hacky, but it is the maven way. It needs to be deployed to a maven repo.
If you keep it in a groupId that you can demonstrably own and it's open source you can publish it to central
I am new to maven, and cannot figure it out.
I have this configuration for the plugin in my pom.xml file, but it looks like mvn does not use my configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
I am getting the same error when I comment out this plugin. There are old discussions on the blogs that maven was ignoring configurations inside the execution. Is it still an issue ? How can I make maven to read my plugin declarations instead of something else? What does it run when my dependency is commented out?
Error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install- plugin:2.3.1:install-file (default-cli) on project core: The parameters 'file' for goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file are missing or invalid -> [Help 1]
From the error message and the information above, one possibility is that you are running mvn install:install-file on your project. Run mvn install instead.