calling celery.send_task() from jython fails when using maven - maven

I have the following Java code that uses Jython to call the celery.send_task() method:
import org.python.util.PythonInterpreter;
public class SendTask {
static final String SEND_TASK_PY =
"from celery import Celery\n"+
"c = Celery('tasks', broker='amqp://', backend='amqp://')\n"+
"c.send_task('tasks.add', args=[2, 2], kwargs={})";
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec(SEND_TASK_PY);
}
}
Which results with the following error:
mvn clean package
java -cp target/jython-celery-0.1-SNAPSHOT-jar-with-dependencies.jar SendTask
Exception in thread "MainThread" Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/home/itaif/dev/jython-celery/target/jython-celery-0.1-SNAPSHOT-jar-with-dependencies.jar/Lib/celery/app/base.py", line 245, in send_task
File "/home/itaif/dev/jython-celery/target/jython-celery-0.1-SNAPSHOT-jar-with-dependencies.jar/Lib/celery/app/amqp.py", line 242, in publish_task
File "/home/itaif/dev/jython-celery/target/jython-celery-0.1-SNAPSHOT-jar-with-dependencies.jar/Lib/kombu/messaging.py", line 155, in publish
File "/home/itaif/dev/jython-celery/target/jython-celery-0.1-SNAPSHOT-jar-with-dependencies.jar/Lib/kombu/messaging.py", line 232, in _prepare
File "/home/itaif/dev/jython-celery/target/jython-celery-0.1-SNAPSHOT-jar-with-dependencies.jar/Lib/kombu/serialization.py", line 170, in encode
File "/home/itaif/dev/jython-celery/target/jython-celery-0.1-SNAPSHOT-jar-with-dependencies.jar/Lib/kombu/serialization.py", line 356, in dumps
TypeError: dumps(): takes no keyword arguments
For reference, here is the maven pom.xml that created the jar file:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jython-celery</groupId>
<artifactId>jython-celery</artifactId>
<packaging>jar</packaging>
<version>0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7-b1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.sf.mavenjython</groupId>
<artifactId>jython-compile-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jython</goal>
</goals>
</execution>
</executions>
<configuration>
<libraries>
<param>Celery</param>
</libraries>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>package-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>SendTask</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

The problem indicated by the error is in the msgpack serializer. By changing the serializer to JSON, the problem disappears.
import org.python.util.PythonInterpreter;
public class SendTask {
static final String SEND_TASK_PY =
"from celery import Celery\n"+
"c = Celery('tasks', broker='amqp://', backend='amqp://')\n"+
"c.conf.CELERY_TASK_SERIALIZER='json'\n"+
"result = c.send_task('tasks.add', args=[2, 2], kwargs={}).get()";
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec(SEND_TASK_PY);
System.out.println(interpreter.get("result"));
} }

Related

Intellij MANIFEST.MF Not able to resolve Main-Class attribute

I am creating an executable jar file for my project and created the MANIFEST.mf file.
I have changed the location of manifest file to src/main/resources
Although the manifest.mf file is auto generated by intellij, it is still showing me error with Main-Class attribute as 'cannot resolve class'.
My main class look like this:
package runner;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
strict=true,
monochrome=false,
features = {"src/test/java/features/ALogin.feature",},
glue = {"steps"},
plugin= {
"html:target/site/cucumber-html",
"json:target/cucumber1.json"}
)
public class TestRunner {
public static void main(String[] args){
String[] arguments={"--glue", "steps"};
cucumber.api.cli.Main.main(arguments);
SecurityManager manager = new IgnoreExitCall();
System.setSecurityManager(manager);
try {
cucumber.api.cli.Main.main(arguments);
} catch (SecurityException s) {
System.out.println("Ignore exit");
}
}
}
My MANIFEST.mf like look like this:
Manifest-Version: 1.0
Main-Class: runner.TestRunner
on hovering over Main-Class, it says cannot resolve class 'runner.TestRunner'.
My pom.xml looks like this:
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>
runner.TestRunner
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

Spring Boot Maven Project Obfuscation with Proguard

I am using Java 11, Spring Boot 2.2.4 and Proguard 6.2.2.
My pom.xml for proguard as follows
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>6.2.2</proguardVersion>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}.jar</outjar>
<includeDependency>true</includeDependency>
<obfuscate>true</obfuscate>
<proguardInclude>${basedir}/proguard.conf</proguardInclude>
<injarNotExistsSkip>true</injarNotExistsSkip>
<libs>
<lib>${java.home}/jmods</lib>
<lib>${java.home}/lib</lib>
</libs>
<archive>
<manifest>
<mainClass>Application</mainClass>
<packageName>com.abc</packageName>
</manifest>
</archive>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>6.2.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.abc.Application</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
My Proguard configuration (proguard.conf) as follows
-ignorewarnings
-dontshrink
-dontoptimize
-keepdirectories
-adaptclassstrings
-useuniqueclassmembernames
-dontusemixedcaseclassnames
-flattenpackagehierarchy 'com.abc'
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
-keep class com.abc.Application
-keep class * extends org.springframework.boot.ApplicationRunner
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclasseswithmembers,includedescriptorclasses,allowshrinking class * {
native <methods>;
}
When I run the obfucated jar, I am getting below error
Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spring-boot-starter-data-jpa-2.2.4.RELEASE.jar
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/spring-boot-starter-data-jpa-2.2.4.RELEASE.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file

Maven plugin - modifying configuration of another plugin

I'm developing custom maven plugin.
My plugin requires a specific configuration for the surefire plugin. As result, as part of my MOJO I'm searching for 'surefire' and if it is present I'm trying to modify its configuration.
My problem is that the configuration is not used.
Here's most of my code:
package io.kuku.agents.plugin;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
/**
* Initialize the integration with the Testing Framework.
*
* #phase test
* #goal initialize-test-listener
* #since 1.0.0
*/
public class SetupMojo extends AbstractKukusMojo {
boolean hasJunit = false;
boolean hasTestNG = false;
public void execute() throws MojoExecutionException, MojoFailureException {
analyzeDependencies();
Plugin surefirePlugin = lookupPlugin("org.apache.maven.plugins:maven-surefire-plugin");
Object config = updateConfiguration(hasJunit, hasTestNG, surefirePlugin.getConfiguration());
surefirePlugin.setConfiguration(config);
List<PluginExecution> executions = surefirePlugin.getExecutions();
for (PluginExecution execution : executions) {
if (execution.getId().equals("default-test")) {
System.out.println("Setting DEFAULT-TEST");
config = updateConfiguration(hasJunit, hasTestNG, execution.getConfiguration());
execution.setConfiguration(config);
break;
}
}
}
private void analyzeDependencies() {
List dependencies = this.project.getDependencies();
for (int i = 0; i < dependencies.size(); i++) {
Dependency dependency = (Dependency) dependencies.get(i);
if (dependency.getArtifactId().equalsIgnoreCase("junit")) {
hasJunit = true;
if (hasJunit && hasTestNG)
break;
else
continue;
}
if (dependency.getArtifactId().equalsIgnoreCase("testng")) {
hasTestNG = true;
if (hasJunit && hasTestNG)
break;
else
continue;
}
}
}
private Object updateConfiguration(boolean hasJunit, boolean hasTestNG, Object configuration) throws MojoExecutionException {
if (configuration == null)
configuration = new Xpp3Dom("configuration");
if (configuration instanceof Xpp3Dom) {
Xpp3Dom xml = (Xpp3Dom) configuration;
Xpp3Dom properties = xml.getChild("properties");
if (properties == null)
{
properties = new Xpp3Dom("properties");
xml.addChild(properties);
}
Xpp3Dom[] property = properties.getChildren("property");
//My logic goes here
...
...
}
return configuration;
}
}
I'll appreciate your help.
N.
EDIT - This is my parent pom:
<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>sllistenertest</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Sl Listener Test (Parent)</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.kuku.on-premise.agents.plugin</groupId>
<artifactId>kuku-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<customerid>nadav2</customerid>
<server>https://fake.kuku.co/api</server>
<appName>fake-app-name</appName>
<moduleName>fake-module-name</moduleName>
<workspacepath>${project.basedir}</workspacepath>
<build>52</build>
<branch>fake-branch</branch>
<packagesincluded>*fklistenertest*</packagesincluded>
<packagesexcluded>com.fake.excluded.*</packagesexcluded>
<filesincluded>*.class</filesincluded>
<logLevel>INFO</logLevel>
<logFolder>c:\fake-log-folder</logFolder>
<logToFile>true</logToFile>
<logEnabled>true</logEnabled>
</configuration>
<executions>
<execution>
<id>a1</id>
<goals>
<goal>build-scanner</goal>
</goals>
</execution>
<execution>
<id>a2</id>
<goals>
<goal>test-listener</goal>
</goals>
</execution>
<execution>
<id>a3</id>
<goals>
<goal>initialize-test-listener</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<!--<configuration>
<properties>
<property>
<name>listener</name>
<value>io.kuku.onpremise.agents.java.agent.integrations.testng.TestListener</value>
</property>
</properties>
<additionalClasspathElements>
<additionalClasspathElement>C:\Temp\kuku-java-1.3.160\artifacts\kuku-api-1.3.160.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>-->
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
<execution>
<id>run-after-antrun</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
<execution>
<id>run-after-antrun</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>Only Junit</module>
<module>Only TestNG</module>
<module>Both</module>
</modules>
</project>
This is the pom for one of the children:
<?xml version="1.0"?>
<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>sllistenertest</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>sllistenertest</groupId>
<artifactId>onlyjunit</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Only JUnit</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.kuku.on-premise.agents.plugin</groupId>
<artifactId>kuku-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
</plugin>
</plugins>
</build>
</project>
You should take a look here:
for JUnit
https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html#Using_Custom_Listeners_and_Reporters
For TestNG:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html#Using_Custom_Listeners_and_Reporters
So i don't see the requirement to implement a plugin...

Deploying running word count on Spark

I have a problem deploying the running word count example for Spark Streaming. I am trying to deploy the same file that is provided with Spark examples, but I want to build and deploy this specific example as a stand alone application.
My file looks like this:
package test;
import scala.Tuple2;
import com.google.common.collect.Lists;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.apache.spark.api.java.function.Function2;
import org.apache.spark.api.java.function.PairFunction;
import org.apache.spark.api.java.StorageLevels;
import org.apache.spark.streaming.Durations;
import org.apache.spark.streaming.api.java.JavaDStream;
import org.apache.spark.streaming.api.java.JavaPairDStream;
import org.apache.spark.streaming.api.java.JavaReceiverInputDStream;
import org.apache.spark.streaming.api.java.JavaStreamingContext;
import java.util.regex.Pattern;
public final class JavaNetworkWordCount {
private static final Pattern SPACE = Pattern.compile(" ");
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Usage: JavaNetworkWordCount <hostname> <port>");
System.exit(1);
}
// Create the context with a 1 second batch size
SparkConf sparkConf = new SparkConf()
.setAppName("JavaNetworkWordCount");
JavaStreamingContext ssc = new JavaStreamingContext(sparkConf,
Durations.seconds(1));
// Create a JavaReceiverInputDStream on target ip:port and count the
// words in input stream of \n delimited text (eg. generated by 'nc')
// Note that no duplication in storage level only for running locally.
// Replication necessary in distributed scenario for fault tolerance.
JavaReceiverInputDStream<String> lines = ssc.socketTextStream(args[0],
Integer.parseInt(args[1]), StorageLevels.MEMORY_AND_DISK_SER);
JavaDStream<String> words = lines
.flatMap(new FlatMapFunction<String, String>() {
public Iterable<String> call(String x) {
return Lists.newArrayList(SPACE.split(x));
}
});
JavaPairDStream<String, Integer> wordCounts = words.mapToPair(
new PairFunction<String, String, Integer>() {
public Tuple2<String, Integer> call(String s) {
return new Tuple2<String, Integer>(s, 1);
}
}).reduceByKey(new Function2<Integer, Integer, Integer>() {
public Integer call(Integer i1, Integer i2) {
return i1 + i2;
}
});
wordCounts.print();
ssc.start();
ssc.awaitTermination();
}
}
And my POM looks like this:
<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>io.tester</groupId>
<artifactId>streamer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>streamer</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.binary.version>2.11</scala.binary.version>
<spark.version>1.4.1</spark.version>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>test.JavaNetworkWordCount</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
The error that I get is:
java.lang.NoClassDefFoundError: com/google/common/collect/Lists
I look through my jar that I built with maven. It has a with-dependencies appended to it, but it doesn't seem to actually have any dependencies in it. I run it via mvn assembly:single. What am I doing wrong?
As the maven-assembly-plugin indicates
If your project wants to package your artifact in an uber-jar, the assembly plugin provides only basic support. For more control, use the Maven Shade Plugin
you can try to use the maven-shade-plugin. Try to replace the maven-assembly-plugin plugin tag with:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>test.JavaNetworkWordCount</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
This should hopefully create a fat jar containing all your dependencies.
I got it figured out. I had two problems. One, I didn't notice that I had the provided clause (stupid cut and paste error). The second problem I had was that one of the dependencies pulled in was signed and I needed to explicitly exclude the signature files. My end product that actually works looks like this in case someone else is having this problem:
<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>io.tester</groupId>
<artifactId>streamer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>streamer</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.binary.version>2.11</scala.binary.version>
<spark.version>1.4.1</spark.version>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>io.tester.streamer.JavaNetworkWordCount</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

maven plugin descriptor not getting generated

I'm creating a maven plugin, MVN clean install build succeeds but plugin.xml is not getting generated.
#Mojo( name = "cover", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
public class RunCoverage extends AbstractMojo
{
#Parameter( property = "cover.wadl", defaultValue = "test")
private String wadl;
#Parameter( property = "cover.endpoints",defaultValue = "test")
private String endpoints;
#Override
public void execute() throws MojoExecutionException
{
<somecode>
}
}
And the pom.xml is
<?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>
<artifactId>end-point-test-coverage</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<phase>process-classes</phase>
</execution>
<execution>
<id>help-descriptor</id>
<goals>
<goal>helpmojo</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Maven clean install doesn't generate plugin.xml
When used in a dependent project, I'm getting the following error
Failed to parse plugin descriptor for it.gruppopam.common:end-point-test-coverage:1 (/home/d/.m2/repository/it/common/end-point-test-coverage/1/end-point-test-coverage-1.jar): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]
[ERROR]
First i would try to set the packaging type to maven-plugin instead of the default which is jar. Furthermore i would suggest to use more up-to-date versions of plugins (maven-compiler-plugin: 3.1) and use a more up-to-date version of maven-plugin-api (3.0? but not 2.0).
you have to remember to change it in your pom.xml to:
<packaging>maven-plugin</packaging>
it is by default:
<packaging>jar</packaging>

Resources