sonar-dotnet-shared-library 由于不存在的依赖项而无法编译,如何使其工作?

sonar-dotnet-shared-library does not compile due non-existing dependencies, How to make it work?

我正在尝试在我的机器上编译 sonar-csharp-plugin,但是在 pom.xml 文件中有两个 Maven public repositories 中不存在的依赖项:

<dependency>
  <groupId>org.sonarsource.dotnet</groupId>
  <artifactId>sonar-dotnet-tests-library</artifactId>
  <version>1.5.0.393</version>
</dependency>
<dependency>
  <groupId>org.sonarsource.dotnet</groupId>
  <artifactId>sonar-dotnet-shared-library</artifactId>
  <version>1.0.1.138</version>
</dependency>

我下载了两个项目的代码并尝试编译它们并为每个项目生成 .jar 文件。

尝试编译 sonar-dotnet-shared-library-1.0.1.138,我安装了 https://www.nuget.org/packages/SonarAnalyzer.CSharp/1.20.0 包,然后在我编译 sonar-dotnet-shared-library 时继续将其安装在我的 maven 本地存储库中-1.0.1.138 我得到:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (unzip-nuget) on project sonar-dotnet-shared-library: An Ant Build Exception has occured: C:\Temp\sonar-dotnet-shared-library-1.0.1.138\target\analyzer\SonarAnalyzer.Scanner\protobuf does not exist.
[ERROR] around Ant part ...<copy todir="src/main/protobuf">... @ 8:35 in C:\Temp\sonar-dotnet-shared-library-1.0.1.138\target\antrun\build-main.xml

我想我在 Maven 地狱里。

我应该怎么做才能从最新版本的 sonar-csharp-plugin 构建代码??

编辑: 当我安装 SonarAnalyzer 时我使用

mvn install:install-file -DgroupId=org.sonarsource.dotnet -DartifactId=SonarAnalyzer.Scanner -Dversion=1.20.0 -Dpackaging=nupkg -Dfile="C:\Temp\SonarAnalyzer.CSharp.1.20.0-RC1.nupkg"

我禁用了生成错误的任务,现在 java 代码开始编译,但我收到与

相关的错误
import org.sonarsource.dotnet.protobuf.SonarAnalyzer;

我认为它是对 SonarAnalyzer Dll 的引用,但 Eclipse 和 Maven 都找不到它(缺少 protobuf)

编辑2:

POM.XML 包括这些任务:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>unzip-nuget</id>
            <phase>validate</phase>
            <configuration>
              <exportAntProperties>true</exportAntProperties>
              <tasks>
                <unzip src="${sonarAnalyzer.workDirectory}/SonarAnalyzer.Scanner.nupkg" dest="${sonarAnalyzer.workDirectory}/SonarAnalyzer.Scanner/" />
                <delete>
                  <fileset dir="src/main/protobuf" excludes=".gitignore"></fileset>
                </delete>
                <copy todir="src/main/protobuf">
                  <fileset dir="${sonarAnalyzer.workDirectory}/SonarAnalyzer.Scanner/protobuf">
                    <include name="*.proto"/>
                  </fileset>
                </copy>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
          <execution>
            <id>compile-protobuf-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <fileset id="fileset" dir="${project.basedir}/src/main/protobuf">
                  <include name="*.proto" />
                </fileset>
                <pathconvert refid="fileset" property="protos" pathsep=" " />
                <mkdir dir="${project.build.directory}/generated-sources/protobuf" />
                <chmod file="${protobuf.compiler}" perm="u+x" />

                <exec failonerror="true" executable="${protobuf.compiler}">
                  <arg value="proto_path=${project.basedir}/src/main/protobuf" />
                  <arg value="java_out=${project.build.directory}/generated-sources/protobuf" />
                  <arg line="${protos}" />
                </exec>  

              </target>
            </configuration>
          </execution>
        </executions>

据我了解,在SonarAnalyzer.Scanner.nupkg中应该是一个protobuf文件夹,并且该文件夹的内容被复制到src/main/protobuf.....那么SonarAnalyzer.Scanner.nupkg下载自Nuget 不包含该文件夹....所以....

Sonar 的朋友们......我从哪里得到那个 nupkg?

我遇到了同样的问题,我在 SonarQube 的 Google 组的 this thread 上找到了解决方案。

您需要从 sonarsource 的 Artifactory 服务器获取丢失的工件。
根据 Duarte Meneses 的建议,您可以将这些行添加到 [user_home]/.m2/settings.xml :

<profiles>
  <profile>
    <id>sonarsource-repo</id>
    <activation>
      <property>
        <name>!skip-sonarsource-repo</name>
      </property>
    </activation>
    <repositories>
      <repository>
        <id>sonarsource</id>
        <name>SonarSource Central Repository</name>
        <url>https://repox.sonarsource.com/sonarsource</url>
        <releases>
          <enabled>true</enabled>
          <updatePolicy>interval:60</updatePolicy>
          <checksumPolicy>fail</checksumPolicy>
        </releases>
        <snapshots>
          <enabled>false</enabled>
          <updatePolicy>never</updatePolicy>
        </snapshots>
      </repository>
    </repositories>
    <pluginRepositories>
      <pluginRepository>
        <id>sonarsource</id>
        <name>SonarSource Central Repository</name>
        <url>https://repox.sonarsource.com/sonarsource</url>
        <releases>
          <enabled>true</enabled>
          <!-- no need to always check if new versions are available when
          executing a maven plugin without specifying the version -->
          <updatePolicy>interval:60</updatePolicy>
          <checksumPolicy>fail</checksumPolicy>
        </releases>
        <snapshots>
          <enabled>false</enabled>
          <updatePolicy>never</updatePolicy>
        </snapshots>
      </pluginRepository>
    </pluginRepositories>
  </profile>
</profiles>

我使用了上面的配置。
我在 settings.xml 中也声明了镜像,所以我不得不从镜像存储库中排除 sonarsource :

<mirrors>
  <mirror>
    <id>nexus</id>
    <mirrorOf>*,!sonarsource</mirrorOf>
    <url>http://ci-server/nexus/content/groups/public</url>
  </mirror>     
</mirrors>

当然还有其他方法可以达到相同的效果,例如在您公司的 Nexus 服务器中声明一个代理存储库。

通过这个配置,我成功搭建了SonarQube