<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 前言 sonar相關的信息分2章,一部分是sonar,一部分是sonar runner,這篇學習的是sonar。 sonar插件依靠于sonar runner插件,且sonar的版本要在2.1.1以上。如果你要執行sonar任務,就在命令行下敲gradle sonarAnalyze。sonarAnalyze任務是獨立存在的,就是該任務來分析代碼,該任務不依靠其他任務。該任務不依靠源碼文件,而是針對class文件和build文件,所以盡量在使用前進行全build。正常情況下,會一天產生一次報告。 # 知識點 ## 1.sonar 插件 ~~~ apply plugin: 'sonar' ~~~ ## 2.配置sonar的服務器和數據庫 在build.gradle添加一個sonar(api中的SonarRootModel)任務,可以配置上面的信息 build.gradle ~~~ sonar{ server{ url = "http://localhost:9002/" } database{ url = "jdbc:mysql://localhost:3306/sonar" driverClassName = "com.mysql.jdbc.Driver" username = "sonar" password = "sonar" } } ~~~ server(api中的SonarServer)里的url代表你在瀏覽器中訪問sonar服務器的地址。 database(api中的SonarDataBase)里代表的是數據庫的信息,包括訪問地址,驅動,用戶名和密碼。 這里面要根據你的實際屬性來填。 ## 3.配置sonar的項目屬性 sonar中的project(api中SonarProject)用來設置如何分析代碼。 跟上面一樣,它也是在sonar任務中添加,如下所示: build.gradle: ~~~ sonar{ server{ url = "http://localhost:9002/" } database{ url = "jdbc:mysql://localhost:3306/sonar" driverClassName = "com.mysql.jdbc.Driver" username = "sonar" password = "sonar" } project { coberturaReportPath = file("$buildDir/cobertura.xml") } } ~~~ ## 4.多項目的分析 在多項目的構建中,你可以在root project項目中配置sonar,讓其分析各個子項目,這樣的速度會比你一個一個單獨分析要快。sonar能夠在頁面上展現出各個項目的樹形結構。sonar中的server和database只需要在根項目配置即可,無需單獨在每個子項目配置一篇。可以通過subprojects任務達到這種效果。但是project的一些自定義的設置需要單獨去配置。例如下面的代碼 ### 設置編碼for每一個子項目 build.gradle ~~~ subprojects { sonar { project { sourceEncoding = "UTF-8" } } } ~~~ 如果你想為某一個特定的子項目設置,可以通過gradle中project任務來設置,格式為project('子項目名'),例如下面的代碼(也是在root project中build.gradle) build.gradle: ### 特定子項目的配置 ~~~ project(":project1") { sonar { project { skip = true } } } ~~~ 上面代碼的作用是在進行sonar分析時,不對project1這個項目進行分析。自然在web頁面中的樹形結構中也就不會顯示該項目。 還有一個語言項,用來配置子項目的編程語言。但是該屬性一個子項目只能有一個語言,不能配置多個語言。下面的例子是為project2設置語言為groovy。 build.gradle ~~~ project(":project2") { sonar { project { language = "groovy" } } } ~~~ 當配置的項只有一項時,下面的語法更簡潔: ~~~ project(":project2").sonar.project.language = "groovy" ~~~ ## 5.分析自定義的Source Set 默認情況下,sonar只會分析項目中main和test這兩個sourceset。你也可以將自己自定義的sourceSets添加到sonar分析的范圍中,這樣sonar就會一并分析了。 你可以通過下面的方式來將自己自定義的sourcesets追加到sonar分析的目錄中: build.gradle: ~~~ sonar.project { sourceDirs += sourceSets.custom.allSource.srcDirs testDirs += sourceSets.integTest.allSource.srcDirs } ~~~ 或者 ~~~ sonar{ server{ url = "http://localhost:9002/" } database{ url = "jdbc:mysql://localhost:3306/sonar" driverClassName = "com.mysql.jdbc.Driver" username = "sonar" password = "sonar" } project { coberturaReportPath = file("$buildDir/cobertura.xml") sourceDirs += sourceSets.custom.allSource.srcDirs testDirs += sourceSets.integTest.allSource.srcDirs } } ~~~ 其中custom和integTest是你自定義的sourceSets。 ## 6.分析非java語言項目 第4點已經講過了,你可以為每一個子項目設置不同的語言。 ## 7.設置sonar自定義屬性 sonar中屬性設置都是以key-value的格式設置的,下面的知識就過一遍吧,對于新手來說,這些東西還太遙遠。只需要記住有2中定義方法,一種是全局定義方式,包括根項目和子項目,還有一種范圍小的,只適用于本項目。分別通過withGlobalProperties和withProjectProperties來定義 ### 全局 build.gradle: ~~~ sonar.withGlobalProperties { props -> props["some.global.property"] = "some value" // non-String values are automatically converted to Strings props["other.global.property"] = ["foo", "bar", "baz"] } ~~~ ### 私有 ~~~ sonar.project.withProjectProperties { props -> props["some.project.property"] = "some value" // non-String values are automatically converted to Strings props["other.project.property"] = ["foo", "bar", "baz"] } ~~~ ## 7.命令行的方式配置sonar (還是不要這么干的好,多累啊) 可設置的屬性如下: server.url:服務器地址 database.url:數據庫地址 database.driverClassName:驅動名 database.username:數據庫用戶名 database.password:數據庫密碼 showSql:打印sql語言 showSqlResults:打印結果 verbose:log級別 forceAnalysis:強制分析 ## 8.執行方式 在命令行下敲下面語句就能執行sonar任務 ~~~ gradle sonarAnalyze ~~~ # 實戰 為什么沒有實戰例子,因為我在公司,你懂的。等晚上再加: ~~~ FAILURE: Build failed with an exception. * What went wrong: Could not resolve all dependencies for configuration ':testCompile'. > Could not resolve junit:junit:4.+. Required by: :TestNG_gradl:1.0 > Failed to list versions for junit:junit. > Unable to load Maven meta-data from https://repo1.maven.org/maven2/juni /junit/maven-metadata.xml. > Could not GET 'https://repo1.maven.org/maven2/junit/junit/maven-meta ata.xml'. > Connection to https://repo1.maven.org refused * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 28.194 secs ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看