0

I am doing repackaging in spring I have encountered an error : Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage (repackage) on project pet-clinic-data: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage failed: Unable to find main class.

Even though I have used true

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <conifguration>
                            <skip>true</skip>
                        </conifguration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

and the pom is set. As I don't have any main class, how to resolve this error

ALready tried .m2/repository deleted all files and clean code again

fedup
  • 1,209
  • 11
  • 26

3 Answers3

1

I solved this problem for me by adding "pluginManagement" tag after "build" tag in both pom.

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                * --- your code or other configurations --- *
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Alternatively, you can also try adding this property in your data module pom

<properties>
    <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
  • Please don't add [the same answer](https://stackoverflow.com/a/72508826/17242583) to multiple questions. Answer the best one and flag the rest as duplicates. See [Is it acceptable to add a duplicate answer to several questions?](//meta.stackexchange.com/q/104227) –  Jun 05 '22 at 16:06
0

When using a multi-module structure, remember that the spring-boot-maven-plugin must be placed in the pom.xml of the module that contains the main class, so that Spring is able to create your jar that, when started, will check that particular class.

If you started the project from Spring Initializr, move this part of code from your main pom.xml to the pom that contains the main class:

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

Also, note that you misspelled "configuration" tag (you wrote "conifguration")

PyroSandro
  • 35
  • 7
0

Under the <build> section, add the <sourceDirectory> and <testSourceDirectory> to specify the module's source code directories to fix this issue.

<build>
    <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <configuration>
                <args>
                    <arg>-Xjsr305=strict</arg>
                </args>
                <compilerPlugins>
                    <plugin>spring</plugin>
                </compilerPlugins>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-allopen</artifactId>
                    <version>${kotlin.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>
iamharish15
  • 1,760
  • 1
  • 17
  • 20