Maven-compiler-plugin引发了所需的编译错误,但阻止了编译进度。

huangapple go评论67阅读模式
英文:

Maven-compiler-plugin throws wanted compile errors but deny the compile progress

问题

几天前我开始使用Maven。我只需要将我生成的jar文件中的一些依赖项放入其中。这是必要的,因为我的代码只是一个插件(Minecraft插件),由API(Minecraft服务器软件Spigot)执行。现在的问题是,我的插件依赖于另一个API(json-simple-1.1)。

过去几天里,我尝试编辑Maven Shade插件以获得所需的结果。我失败了,现在我是这样做的:

  • Maven包含我插件所需的json-simple-1.1 API
  • Eclipse包含Spigot API(Minecraft服务器软件),将执行我的插件

pom.xml:

<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>de.falco.essentialsXXX</groupId>
  <artifactId>EssentialsXXX-bungeecord</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <description>Basic class for every Plugin</description>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <!-- COMPILE -->
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <!-- BUILD -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-json</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.googlecode.json-simple</groupId>
      <artifactId>json-simple</artifactId>
      <version>1.1.1</version>
    </dependency>
  </dependencies>
</project>
<!-- end snippet -->

当我现在在正确的目录中执行'mvn clean install'时,会出现许多错误。这完全合理。Maven找不到来自Spigot API的类型或类以及其他一切。
我的问题是,这不是真正的错误,因为当Spigot API执行我的插件时,我会获得所需的类和类型。Maven不知道这一点,不会编译我的程序:(
在这一点上,我不知道该怎么办。我阅读了很多文章,但找不到解决方案。每篇文章都说,哦,这里有一个错误,尝试使用标签和正确的API值。但这不是我需要的。

我需要像编译器的“bypass”属性一样的东西,这样编译器就知道,“是的,这是一个错误,但编码人员知道自己在做什么”。

英文:

A few days ago i started with Maven. I have to put only a few of my dependencies in my generated jar file. This is needed because my code is only a plugin (Minecraft Plugin) executed by an api (Minecraft Server Software Spigot). Now the Problem is, that my Plugin depends on an other api (json-simple-1.1).

The last days i tried to edit the maven shade plugin to get the wished result. I failed, and now i did it in this way:

  • maven include the json-simple-1.1 api, i needing for my plugin
  • eclipse include the spigot api (Minecraft server software), which will executing my plugin

pom.xml:
<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;de.falco.essentialsXXX&lt;/groupId&gt;
  &lt;artifactId&gt;EssentialsXXX-bungeecord&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;description&gt;Basic class for every Plugin
&lt;/description&gt;
  &lt;build&gt;
  
    &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
    
    &lt;!-- COMPILE --&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;version&gt;3.8.0&lt;/version&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.8&lt;/source&gt;
          &lt;target&gt;1.8&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      
      &lt;!-- BUILD --&gt;
      
	  &lt;plugin&gt;
	  
	    &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
		&lt;version&gt;3.1.0&lt;/version&gt;
		
		&lt;configuration&gt;
		
		
		  &lt;descriptorRefs&gt;
			&lt;descriptorRef&gt;jar-with-json&lt;/descriptorRef&gt;
		  &lt;/descriptorRefs&gt;
		
		&lt;/configuration&gt;
		
		&lt;executions&gt;
		
			&lt;execution&gt;
			
				&lt;id&gt;make-assembly&lt;/id&gt;
				&lt;phase&gt;package&lt;/phase&gt;
				&lt;goals&gt;
					&lt;goal&gt;single&lt;/goal&gt;
				&lt;/goals&gt;
			
			&lt;/execution&gt;
		
		&lt;/executions&gt;
	  
	  &lt;/plugin&gt;
      
    &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;dependencies&gt;
  
  	&lt;dependency&gt;
    	&lt;groupId&gt;com.googlecode.json-simple&lt;/groupId&gt;
    	&lt;artifactId&gt;json-simple&lt;/artifactId&gt;
    	&lt;version&gt;1.1.1&lt;/version&gt;
	&lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  
&lt;/project&gt;

<!-- end snippet -->

When i now execute 'mvn clean install' (in the right directory) i get many many errors. That make completely sense. Maven can not find types or classes and everything else comeing from the spigot-api.
My Problem is, that this isnt a real error because when the spigot-api execute my plugin i have the classes and types i need. Maven dont know that and dont compile my Programm Maven-compiler-plugin引发了所需的编译错误,但阻止了编译进度。
At this point a have no idea what to do. I read so many articles but i couldnt find a solution. Every article say ohhh an error here try to use <depdency> tags and the right api values. That isnt what i need.

I need something like a "bypass" attribute for the compiler so the compiler know "yes this is an error but the coder knows what he does"

答案1

得分: 0

如果您需要用于编译的内容,它需要是一个Maven依赖项。

因此,获取该构件,将其安装到您的本地仓库,并将其添加为依赖。

然后您的编译过程可能会正常工作。

请注意,使用依赖项并不意味着您必须将该依赖项包含在生成的jar包中。

英文:

If you need something for compilation, it needs to be a Maven dependency.

So take that artifact, install it in your local repository and add it as dependency.

Then your compilation process will probably work.

Note that using a dependency does not mean that you have to include the dependency into the resulting jar.

huangapple
  • 本文由 发表于 2020年7月25日 19:43:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63087918.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定