3

I was trying to run the Hello World example from Spring Boot. When I run 'mvn package' on the module I get the following error:-

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project spring.boot: Unable to parse configuration of mojo org.apache.maven.plugins:maven->shade->plugin:2.1:shade for parameter transformer: Cannot find setter, adder nor field in org.apache.maven.plugins.shade.resource.ManifestResourceTransformer for 'resource' -> [Help 1]

I haven't used any 'resource' attribute, but it seems to complain about this. Any idea what I am doing wrong here

Here is the pom for the module:-

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework</groupId>
    <artifactId>spring.boot</artifactId>
    <version>0.1.0</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.1.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>hello.SampleController</Main-Class>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
Dave Syer
  • 56,583
  • 10
  • 155
  • 143
Dhiraj
  • 550
  • 6
  • 14

2 Answers2

6

The first thing you could try is to not use the shade plugin (it's an inferior solution in general to the spring-boot plugin). The spring-boot plugin should be the one you find in all samples and guides in spring.io. With the starter-parent in use it's pretty trivial:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The parent has a configuration for ManifestResourceTransformer already, so I assume that's the problem. If you remove the <executions/> and set a property start-class it should work.

If you need to use shade for some reason and you want to take control of the configuration, then don't use the starter-parent as a parent (maybe just use it for dependency management).

Dave Syer
  • 56,583
  • 10
  • 155
  • 143
  • Could you please tell the way how can I build executable jar not using shade plugin? – ieXcept Mar 28 '17 at 16:16
  • You need to be aware of some packaging differences here. If you are using version >= 1.4.x of Spring Boot, the plugin changed to package the files under `BOOT-INF/classes`, _not_ at the root of the JAR file. If you execute the JAR file in a way that expects the files to be at the root of the JAR file, execution will fail. – Jack Straw Jul 11 '17 at 23:20
-1

In my case, I use Command Prompt (cmd.exe) to package the project. When maven packs the project, it will download all plugins, dependencies (Apache Maven Shade Plugin in this case). Cd to your project. Type:

mvn package

After packaging, it works. Hope it helps.

Hung Dam
  • 109
  • 1
  • 3