Skip to content

Instantly share code, notes, and snippets.

@ashishraste
Last active June 24, 2019 05:12
Show Gist options
  • Select an option

  • Save ashishraste/54ff593b4ccda04cc60d65fe3f0b5f4a to your computer and use it in GitHub Desktop.

Select an option

Save ashishraste/54ff593b4ccda04cc60d65fe3f0b5f4a to your computer and use it in GitHub Desktop.
Snippets for Java based repos

Java Snippets

Packaging SpringBoot App in a Docker Image

Requires a repackage goal in the spring-boot-maven plugin, as given below.

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${springboot.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
</build>

SonarQube coverage profile in a POM file

Requires Jacoco plugin to send coverage report to a SonarQube server.

<project>
...
  <profiles>
    <profile>
      <id>sonar-coverage</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.jacoco</groupId>
              <artifactId>jacoco-maven-plugin</artifactId>
              <version>${jacoco.plugin.version}</version>
            </plugin>
          </plugins>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <configuration>
              <append>true</append>
            </configuration>
            <executions>
              <execution>
                <id>agent-for-unit-tests</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>agent-for-integration-tests</id>
                <goals>
                  <goal>prepare-agent-integration</goal>
                </goals>
              </execution>
              <execution>
                <id>jacoco-site</id>
                <phase>verify</phase>
                <goals>
                  <goal>report</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
...
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment