ArrayOutOfBounds compiling maven plugin on netbeans
I'm trying to compile a very simple maven plugin, that essentially copies the contents from one folder to another, but an ArrayOutOfBoundsException
keeps being thrown at compile time by some class that (I guess) process the annotations. I'll paste below the logs from the compiler, the plugin class and the POM.
Do you think that could be a bug in the tool?
How could I solve this?
compiler logs
mvn -X clean deploy
...
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy', parentClassName='org.codehaus.plexus.classworlds.strategy.AbstractStrategy', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.Strategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.Strategy', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.StrategyFactory:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.StrategyFactory', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.869 s
Finished at: 2019-01-03T14:37:45-02:00
Final Memory: 15M/54M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 49272
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scanDirectory(DefaultMojoAnnotationsScanner.java:204)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:95)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:125)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:104)
at org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:108)
at org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:233)
at org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:92)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
the plugin class
@Mojo(name = "backup")
public class Backup extends AbstractMojo {
private Log log;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
log = getLog();
File destination = generateFile("backup"),
source = generateFile("src", "main", "webapp", "files");
log.info(destination.getAbsolutePath());
log.info(Boolean.toString(destination.exists()));
if (destination.exists()) {
log.info("removing pre-encountered ./backup folder");
try {
Files.walk(destination.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
if (!destination.delete()) {
throw new IOException("Impossible to delete folder.");
}
} catch (IOException ex) {
log.error("Error deleting previous backup folder");
throw new MojoExecutionException("Impossible to delete previous backup folder.", ex);
}
}
log.debug("attempting to create ./backup dir");
if (destination.mkdir()) {
try {
log.info("Beginning backup.");
recursiveCopy(source, destination);
} catch (IOException ex) {
log.error("error copying files", ex);
throw new MojoExecutionException("Error copying files", ex);
}
} else {
log.error("unable to create ./backup directory");
throw new MojoExecutionException("unable to create ./backup directory");
}
log.debug("backup finished");
}
private void recursiveCopy(File source, File destination) throws IOException {
for (File file : source.listFiles()) {
if (file.isDirectory()) {
log.debug(generateString("creating folder ", file.getName()));
File newDest = generateFile(destination.getPath(), file.getName());
if (newDest.mkdir()) {
recursiveCopy(file, newDest);
} else {
String error = generateString("Unable to create folder ", file.getPath());
log.error(error);
throw new IOException(error);
}
} else {
log.debug(generateString("copying ", file.getPath()));
Files.copy(file.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
static String generateString(String... sts) {
StringBuilder out = new StringBuilder();
Arrays.stream(sts).forEach(out::append);
return out.toString();
}
static File generateFile(String... paths) {
String paths2 = new String[paths.length * 2 - 1];
paths2[0] = paths[0];
for (int i = 1, j = 1; i < paths2.length; i++, j++) {
paths2[i] = File.separator;
paths2[++i] = paths[j];
}
return new File(generateString(paths2));
}
}
in case you're wondering why I did those stupid methods at the bottom, its because some how they were avoiding this error (using direct string concatenation was one of the causes I foud)
and my POM
... version, id and stuff ...
<packaging>maven-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
java arrays maven exception maven-plugin
add a comment |
I'm trying to compile a very simple maven plugin, that essentially copies the contents from one folder to another, but an ArrayOutOfBoundsException
keeps being thrown at compile time by some class that (I guess) process the annotations. I'll paste below the logs from the compiler, the plugin class and the POM.
Do you think that could be a bug in the tool?
How could I solve this?
compiler logs
mvn -X clean deploy
...
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy', parentClassName='org.codehaus.plexus.classworlds.strategy.AbstractStrategy', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.Strategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.Strategy', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.StrategyFactory:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.StrategyFactory', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.869 s
Finished at: 2019-01-03T14:37:45-02:00
Final Memory: 15M/54M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 49272
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scanDirectory(DefaultMojoAnnotationsScanner.java:204)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:95)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:125)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:104)
at org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:108)
at org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:233)
at org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:92)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
the plugin class
@Mojo(name = "backup")
public class Backup extends AbstractMojo {
private Log log;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
log = getLog();
File destination = generateFile("backup"),
source = generateFile("src", "main", "webapp", "files");
log.info(destination.getAbsolutePath());
log.info(Boolean.toString(destination.exists()));
if (destination.exists()) {
log.info("removing pre-encountered ./backup folder");
try {
Files.walk(destination.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
if (!destination.delete()) {
throw new IOException("Impossible to delete folder.");
}
} catch (IOException ex) {
log.error("Error deleting previous backup folder");
throw new MojoExecutionException("Impossible to delete previous backup folder.", ex);
}
}
log.debug("attempting to create ./backup dir");
if (destination.mkdir()) {
try {
log.info("Beginning backup.");
recursiveCopy(source, destination);
} catch (IOException ex) {
log.error("error copying files", ex);
throw new MojoExecutionException("Error copying files", ex);
}
} else {
log.error("unable to create ./backup directory");
throw new MojoExecutionException("unable to create ./backup directory");
}
log.debug("backup finished");
}
private void recursiveCopy(File source, File destination) throws IOException {
for (File file : source.listFiles()) {
if (file.isDirectory()) {
log.debug(generateString("creating folder ", file.getName()));
File newDest = generateFile(destination.getPath(), file.getName());
if (newDest.mkdir()) {
recursiveCopy(file, newDest);
} else {
String error = generateString("Unable to create folder ", file.getPath());
log.error(error);
throw new IOException(error);
}
} else {
log.debug(generateString("copying ", file.getPath()));
Files.copy(file.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
static String generateString(String... sts) {
StringBuilder out = new StringBuilder();
Arrays.stream(sts).forEach(out::append);
return out.toString();
}
static File generateFile(String... paths) {
String paths2 = new String[paths.length * 2 - 1];
paths2[0] = paths[0];
for (int i = 1, j = 1; i < paths2.length; i++, j++) {
paths2[i] = File.separator;
paths2[++i] = paths[j];
}
return new File(generateString(paths2));
}
}
in case you're wondering why I did those stupid methods at the bottom, its because some how they were avoiding this error (using direct string concatenation was one of the causes I foud)
and my POM
... version, id and stuff ...
<packaging>maven-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
java arrays maven exception maven-plugin
Define the maven-plugin-plugin with the most recent version...furthermore use<maven.compiler.release>10</maven.compiler.release>
instead of source/target and make sure your are using the most recent version of maven-compiler-plugin (3.8.0)...
– khmarbaise
Jan 3 at 17:27
did it, but changed to aNullPointerException
at the same place
– Lucas Noetzold
Jan 3 at 17:44
add a comment |
I'm trying to compile a very simple maven plugin, that essentially copies the contents from one folder to another, but an ArrayOutOfBoundsException
keeps being thrown at compile time by some class that (I guess) process the annotations. I'll paste below the logs from the compiler, the plugin class and the POM.
Do you think that could be a bug in the tool?
How could I solve this?
compiler logs
mvn -X clean deploy
...
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy', parentClassName='org.codehaus.plexus.classworlds.strategy.AbstractStrategy', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.Strategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.Strategy', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.StrategyFactory:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.StrategyFactory', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.869 s
Finished at: 2019-01-03T14:37:45-02:00
Final Memory: 15M/54M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 49272
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scanDirectory(DefaultMojoAnnotationsScanner.java:204)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:95)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:125)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:104)
at org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:108)
at org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:233)
at org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:92)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
the plugin class
@Mojo(name = "backup")
public class Backup extends AbstractMojo {
private Log log;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
log = getLog();
File destination = generateFile("backup"),
source = generateFile("src", "main", "webapp", "files");
log.info(destination.getAbsolutePath());
log.info(Boolean.toString(destination.exists()));
if (destination.exists()) {
log.info("removing pre-encountered ./backup folder");
try {
Files.walk(destination.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
if (!destination.delete()) {
throw new IOException("Impossible to delete folder.");
}
} catch (IOException ex) {
log.error("Error deleting previous backup folder");
throw new MojoExecutionException("Impossible to delete previous backup folder.", ex);
}
}
log.debug("attempting to create ./backup dir");
if (destination.mkdir()) {
try {
log.info("Beginning backup.");
recursiveCopy(source, destination);
} catch (IOException ex) {
log.error("error copying files", ex);
throw new MojoExecutionException("Error copying files", ex);
}
} else {
log.error("unable to create ./backup directory");
throw new MojoExecutionException("unable to create ./backup directory");
}
log.debug("backup finished");
}
private void recursiveCopy(File source, File destination) throws IOException {
for (File file : source.listFiles()) {
if (file.isDirectory()) {
log.debug(generateString("creating folder ", file.getName()));
File newDest = generateFile(destination.getPath(), file.getName());
if (newDest.mkdir()) {
recursiveCopy(file, newDest);
} else {
String error = generateString("Unable to create folder ", file.getPath());
log.error(error);
throw new IOException(error);
}
} else {
log.debug(generateString("copying ", file.getPath()));
Files.copy(file.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
static String generateString(String... sts) {
StringBuilder out = new StringBuilder();
Arrays.stream(sts).forEach(out::append);
return out.toString();
}
static File generateFile(String... paths) {
String paths2 = new String[paths.length * 2 - 1];
paths2[0] = paths[0];
for (int i = 1, j = 1; i < paths2.length; i++, j++) {
paths2[i] = File.separator;
paths2[++i] = paths[j];
}
return new File(generateString(paths2));
}
}
in case you're wondering why I did those stupid methods at the bottom, its because some how they were avoiding this error (using direct string concatenation was one of the causes I foud)
and my POM
... version, id and stuff ...
<packaging>maven-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
java arrays maven exception maven-plugin
I'm trying to compile a very simple maven plugin, that essentially copies the contents from one folder to another, but an ArrayOutOfBoundsException
keeps being thrown at compile time by some class that (I guess) process the annotations. I'll paste below the logs from the compiler, the plugin class and the POM.
Do you think that could be a bug in the tool?
How could I solve this?
compiler logs
mvn -X clean deploy
...
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy', parentClassName='org.codehaus.plexus.classworlds.strategy.AbstractStrategy', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.Strategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.Strategy', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.StrategyFactory:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.StrategyFactory', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.869 s
Finished at: 2019-01-03T14:37:45-02:00
Final Memory: 15M/54M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 49272
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scanDirectory(DefaultMojoAnnotationsScanner.java:204)
at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:95)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:125)
at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:104)
at org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:108)
at org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:233)
at org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:92)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
the plugin class
@Mojo(name = "backup")
public class Backup extends AbstractMojo {
private Log log;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
log = getLog();
File destination = generateFile("backup"),
source = generateFile("src", "main", "webapp", "files");
log.info(destination.getAbsolutePath());
log.info(Boolean.toString(destination.exists()));
if (destination.exists()) {
log.info("removing pre-encountered ./backup folder");
try {
Files.walk(destination.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
if (!destination.delete()) {
throw new IOException("Impossible to delete folder.");
}
} catch (IOException ex) {
log.error("Error deleting previous backup folder");
throw new MojoExecutionException("Impossible to delete previous backup folder.", ex);
}
}
log.debug("attempting to create ./backup dir");
if (destination.mkdir()) {
try {
log.info("Beginning backup.");
recursiveCopy(source, destination);
} catch (IOException ex) {
log.error("error copying files", ex);
throw new MojoExecutionException("Error copying files", ex);
}
} else {
log.error("unable to create ./backup directory");
throw new MojoExecutionException("unable to create ./backup directory");
}
log.debug("backup finished");
}
private void recursiveCopy(File source, File destination) throws IOException {
for (File file : source.listFiles()) {
if (file.isDirectory()) {
log.debug(generateString("creating folder ", file.getName()));
File newDest = generateFile(destination.getPath(), file.getName());
if (newDest.mkdir()) {
recursiveCopy(file, newDest);
} else {
String error = generateString("Unable to create folder ", file.getPath());
log.error(error);
throw new IOException(error);
}
} else {
log.debug(generateString("copying ", file.getPath()));
Files.copy(file.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
static String generateString(String... sts) {
StringBuilder out = new StringBuilder();
Arrays.stream(sts).forEach(out::append);
return out.toString();
}
static File generateFile(String... paths) {
String paths2 = new String[paths.length * 2 - 1];
paths2[0] = paths[0];
for (int i = 1, j = 1; i < paths2.length; i++, j++) {
paths2[i] = File.separator;
paths2[++i] = paths[j];
}
return new File(generateString(paths2));
}
}
in case you're wondering why I did those stupid methods at the bottom, its because some how they were avoiding this error (using direct string concatenation was one of the causes I foud)
and my POM
... version, id and stuff ...
<packaging>maven-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
java arrays maven exception maven-plugin
java arrays maven exception maven-plugin
edited Jan 3 at 17:19
Lucas Noetzold
asked Jan 3 at 17:04
Lucas NoetzoldLucas Noetzold
5221612
5221612
Define the maven-plugin-plugin with the most recent version...furthermore use<maven.compiler.release>10</maven.compiler.release>
instead of source/target and make sure your are using the most recent version of maven-compiler-plugin (3.8.0)...
– khmarbaise
Jan 3 at 17:27
did it, but changed to aNullPointerException
at the same place
– Lucas Noetzold
Jan 3 at 17:44
add a comment |
Define the maven-plugin-plugin with the most recent version...furthermore use<maven.compiler.release>10</maven.compiler.release>
instead of source/target and make sure your are using the most recent version of maven-compiler-plugin (3.8.0)...
– khmarbaise
Jan 3 at 17:27
did it, but changed to aNullPointerException
at the same place
– Lucas Noetzold
Jan 3 at 17:44
Define the maven-plugin-plugin with the most recent version...furthermore use
<maven.compiler.release>10</maven.compiler.release>
instead of source/target and make sure your are using the most recent version of maven-compiler-plugin (3.8.0)...– khmarbaise
Jan 3 at 17:27
Define the maven-plugin-plugin with the most recent version...furthermore use
<maven.compiler.release>10</maven.compiler.release>
instead of source/target and make sure your are using the most recent version of maven-compiler-plugin (3.8.0)...– khmarbaise
Jan 3 at 17:27
did it, but changed to a
NullPointerException
at the same place– Lucas Noetzold
Jan 3 at 17:44
did it, but changed to a
NullPointerException
at the same place– Lucas Noetzold
Jan 3 at 17:44
add a comment |
1 Answer
1
active
oldest
votes
solved by explicitly adding a run for the maven-plugin-plugin::descriptor to the POM
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
not sure why...
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026707%2farrayoutofbounds-compiling-maven-plugin-on-netbeans%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
solved by explicitly adding a run for the maven-plugin-plugin::descriptor to the POM
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
not sure why...
add a comment |
solved by explicitly adding a run for the maven-plugin-plugin::descriptor to the POM
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
not sure why...
add a comment |
solved by explicitly adding a run for the maven-plugin-plugin::descriptor to the POM
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
not sure why...
solved by explicitly adding a run for the maven-plugin-plugin::descriptor to the POM
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
not sure why...
answered Jan 4 at 0:10
Lucas NoetzoldLucas Noetzold
5221612
5221612
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026707%2farrayoutofbounds-compiling-maven-plugin-on-netbeans%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Define the maven-plugin-plugin with the most recent version...furthermore use
<maven.compiler.release>10</maven.compiler.release>
instead of source/target and make sure your are using the most recent version of maven-compiler-plugin (3.8.0)...– khmarbaise
Jan 3 at 17:27
did it, but changed to a
NullPointerException
at the same place– Lucas Noetzold
Jan 3 at 17:44