maven-resources-plugin将资源副本分解为测试类

时间:2015-01-21 15:39:21

标签: maven maven-resources-plugin

通常,我的POM文件工作正常,所有单元测试都通过,所有工件都正确打包。但是,一旦我添加了这个maven-resources-plugin以根据配置文件创建特定配置,我的所有测试都会失败,因为'src / test / resources'中没有任何内容被复制到'test-classes':

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <overwrite>true</overwrite>
                <outputDirectory>${project.build.directory}/${config.dir}/${project.activeProfiles[1].id}</outputDirectory>
                <resources>
                    <filtering>true</filtering>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </configuration>
        </plugin>   

我不明白为什么会阻止复制测试资源。有什么想法吗?

3 个答案:

答案 0 :(得分:1)

经过多次反复试验,我找到了解决方案。 maven-resources-plugin需要附加到流程资源阶段,以便按预期解决所有问题。现在,这可能不是最好的答案,但它对我有用。如果您有更好的解决方案,请告诉我。

<executions>
  <execution>
     <id>create specific server configuration</id> 
     <phase>process-resources</phase> 
     <goals>
       <goal>resources</goal> 
     </goals>
    <configuration>
    /** as above **/
    </configuration>
  </execution>
</executions>

答案 1 :(得分:0)

我相信你需要添加一些配置:

<testResources>
    <testResource><directory>src/test/resources</directory></testResource>
</testResources>

答案 2 :(得分:0)

问题是您正在尝试将测试资源作为主要资源,而不是测试资源。

我用这段代码完成了它:

public class MainActivity extends Activity {
    RadioGroup rg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rg = (RadioGroup)findViewById(R.id.radioGroup1);  // getting null

        rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                System.out.println(">>>>>>>>> "+rg);
            }
        });
    }
}

///--------------------------------------------------------

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="49dp"
    android:layout_marginTop="14dp" >

    <RadioButton
        android:id="@+id/radio0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radio1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radio2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />

</RadioGroup>

Please any one help me to resolve this error plz....
Thanks in advance  
相关问题