#creating maven plugin
1 messages ยท Page 1 of 1 (latest)
โ This post has been reserved for your question.
Hey @winged bone! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
๐
and you can probably also configure more
now it also created a test class that fails...
Did you run mvn verify before making any changes?
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.13.1:helpmojo (help-goal) on project maven-plugin-test: You need to specify a goalPrefix as it can not be correctly computed -> [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
oop
Can you show the full output?
Is there an mvnw file?
nope
Can you show the pom.xml?
<version>3.7.0</version> at the bottom seems to throw an error
Can you run mvn test?
It is possible that it fails because you are running it from IntelliJ
since the integration tests are running Maven on other projects to check the plugin working correctly
Can you run C:\Program Files\JetBrains\IntelliJ IDEA 2024.2.3\plugins\maven\lib\maven3\bin\mvn verify -X?
or however you run programs with spaces in the path on Windows
"C:\Program Files\JetBrains\IntelliJ IDEA 2024.2.3\plugins\maven\lib\maven3\bin\mvn" verify -X should be like this and it says that it doesnt recognize verify
What's the exact wording?
its in italian ๐
+ ... ns\IntelliJ IDEA 2024.2.3\plugins\maven\lib\maven3\bin\mvn" verify -X
+ ~~~~~~
Token 'verify' imprevisto nell'espressione o nell'istruzione.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
"Token 'verify' unexpected in the expression or instruction"
ok that's a PowerShell error
Can you add a & at the beginning of the command? so & "C:\..."
I don't use Windows though lol
and especially not PowerShell
ooh ok it ran but theres no visible output in the terminal
Can you try that one in cmd instead of PowerShell?
Alternatively it might not be mvn but mvn.bat or mvn.cmd - try using autocomplete
The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program.
from the powershell
oh you don't even have a Java installation configuted outside of IntelliJ
that means you were able to run Maven but it wanted a Java installation
Can you press the ctrl key twice in IntelliJ?
that should pop up a text field I think
yep
this is the full log
You need to specify a goalPrefix as it can not be correctly computed
this is what causes the error
sounds like your plugin misses some configuration
add this to the <configuration> of the maven-plugin-plugin:
<goalPrefix>YOUR_PLUGIN_PREFIX</goalPrefix>
idk if this causes some of the errors but i copied the pom acactly from here
https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-invoker-plugin/3.9.0
with YOUR_PLUGIN_PREFIX being replaced by the short nane of your plugin - goals would then be invoked with mvn YOUR_PLUGIN_PREFIX:YOUR_GOAL_NAME
that's just IntelliJ lying to you and it's kinda normal
once the CLI build works, you can reload the Maven project in IntelliJ and it should realise the plugin exists
verify works!
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.13.1</version>
<configuration>
<goalPrefix>test</goalPrefix>
</configuration>
</plugin>
so mvn com.ale:test ?
Can you show your mojo class?
package com.ale;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* Goal which touches a timestamp file.
*/
@Mojo( name = "touch", defaultPhase = LifecyclePhase.PROCESS_SOURCES )
public class MyMojo
extends AbstractMojo
{
/**
* Location of the file.
*/
@Parameter( defaultValue = "${project.build.directory}", property = "outputDir", required = true )
private File outputDirectory;
public void execute()
throws MojoExecutionException
{
File f = outputDirectory;
if ( !f.exists() )
{
f.mkdirs();
}
File touch = new File( f, "touch.txt" );
FileWriter w = null;
try
{
w = new FileWriter( touch );
w.write( "touch.txt" );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error creating file " + touch, e );
}
finally
{
if ( w != null )
{
try
{
w.close();
}
catch ( IOException e )
{
// ignore
}
}
}
}
}
then you can reload the Maven project in IntelliJ to get rid of the visual error/IntelliJ lying about the plugin not existing - if you still have that
hmm i reloaded but its still there
your goalPrefix is test and your mojo name is touch so you could run mvn test:touch in a project using the plugin
mvn -Prun-its verify
-Prun-its activates the run-its profile
which should force the invoker plugin to be downloaded (and it should also run the integration tests for the plugin which is how you'd test the plugin)
[ERROR] The following builds failed:
[ERROR] * simple-it\pom.xml
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.486 s
[INFO] Finished at: 2025-05-24T00:55:32+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-invoker-plugin:3.9.0:verify (integration-test) on project maven-plugin-test: 1 build failed. See console output above for details. -> [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/MojoFailureException
tho it did remove the error from the other pom which is nice :)
the pom that's throwing the error is this
<?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.ale.it</groupId>
<artifactId>simple-it</artifactId>
<version>1.0-SNAPSHOT</version>
<description>A simple IT verifying the basic use case.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>touch</id>
<phase>validate</phase>
<goals>
<goal>touch</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
no output before that?
yep
Is there a rouch.txt anywhere?
touch.txt*
probably in the target directory of the integration test project
or something like that
no there isnt :I
maybe in target of the main project there's a directory for the test with another target directory
Is there a simple-it\target directory?
i created one insrc/it/simple-it/touch.txt and it did get pasted in the target
I mean the plugin is supposed to create that file but in a different location
Is there really no src/it/simple-it/target directory? Check in the Windows explorer, not just in IntelliJ
Are there any other target directories?
no
there's this one but its outside src
The purpose of the sample plugin is to create that file and it seems like it doesn't - your plugin would probably do something else :)
ok yes if the touch.txt wasn't created by you, it means the plugin worked
but idk why the test didn't work lol
So you have a working plugin - but the test seems to have some issues
If in doubt, blame someone/something else - so I blame ... Windows!
no that was generated by maven when i put the touch.txt here
i deleted this and reran mvn -Prun-its verify and now it doesnt get generated
Can you run mvn -Prun-its clean verify?
that should delete all the output files first
it says it cant find the file
Can you select your main project pom.xml and run that command again?
oh ok now it runs
same error from test fail as before tho, no file found in target/..
theres no target/its/simple-it/target folder
ughh i need to go to sleep... i'll look for another approach tomorrow or maybe even how to make a gradle plugin.
I appreciate the help so far tho, thank you very much
thanks โค๏ธ