Shryne / Ai_System

A program that lets some ai's play some games and shows their performance doing that
MIT License
0 stars 0 forks source link

Add sonarcloud #2

Closed Shryne closed 5 years ago

Shryne commented 5 years ago

Sonarcloud must be added to keep the code quality high.

Shryne commented 5 years ago

Since Sonarcloud asked me about whether I want to use TravisCI and since Travis is free for opensource projects I added it, too.

Shryne commented 5 years ago

Adding Travis: 1) Click on + for the repositories
2) Click on the project to add (in this case AI_System)
3) Install Ruby to encrypt the travis key provided by Sonarcloud (https://rubyinstaller.org/downloads/)
4) Ruby asks what should be included. Since I have no idea what Travis needs I took all.
5) gem install travis and following the installation should be enough.
6) Move to the folder of the project (in the console).
7) Use the command provided by sonarcloud (something like travis encrypt ).
8) The rest should be explained by sonarcloud and the console.

Shryne commented 5 years ago

Sonarcloud didn't need any pom.xml configuration (at least not the stuff I put in there in other projects).

Shryne commented 5 years ago

Jacoco was a pain - as always. I had a lot of trouble getting the coverage report in jacoco and then to sonarcloud. This is what I did:

The pom.xml file got this:

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.3</version>
            <configuration>
                <append>true</append>
            </configuration>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>prepare-agent-integration</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>

and (maybe) this:

<properties>
    <!-- sonar cloud stuff -->
    <sonar.sources>src/main/java</sonar.sources>
    <sonar.tests>src/test/java</sonar.tests>
    <runSuite>**/*Suite.class</runSuite>
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
    <sonar.language>kotlin</sonar.language> // or java when java is used

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

The .travis.yml file gets this:

script:
  # the following command line builds the project, runs the tests with coverage and then execute the SonarCloud analysis
  # Yes, it has to be this long and inside one row...
  - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify org.jacoco:jacoco-maven-plugin:report sonar:sonar -Dsonar.projectKey=<the project>