我有一个Scala / Akka项目,我正在使用Maven构建。
我有一个存储常量和配置的文件:
/src/main/resources/reference.conf
但是,现在,我创建了一个父Maven模块和一个子Maven模块。
因此文件移至:
child-project/src/main/resources/reference.conf
现在,当我尝试使用reference.conf
中的常量时,就像这样:
system.settings.config.getConfig("some-constant")
我收到此错误:
No configuration setting found for key 'some-constant'.
在查看此处No configuration setting found for key 'akka.version'后,我使用了maven-shade-plugin
,但没有效果。
在主pom.xml
我有这个可能相关的配置:
<build>
<sourceDirectory>child-project/src/main/scala</sourceDirectory>
<testSourceDirectory>child-project/src/test/scala</testSourceDirectory>
</build>
父模块中的pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>parent-project</groupId>
<artifactId>my.package.name</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent project</name>
<modules>
<module>child-project</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<scalaVersion>2.11.8</scalaVersion>
<scalaMajorVersion>2.11</scalaMajorVersion>
<akkaVersion>2.4.14</akkaVersion>
<scalaMavenVersion>3.2.1</scalaMavenVersion>
<akkaHttpVersion>10.0.0</akkaHttpVersion>
<scalacticVersion>3.0.1</scalacticVersion>
<scalatestVersion>3.0.1</scalatestVersion>
</properties>
<build>
<sourceDirectory>child-project/src/main</sourceDirectory>
<testSourceDirectory>child-project/src/test</testSourceDirectory>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scalaMavenVersion}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scalaVersion}</scalaVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
<includes>
<include>**/*Spec.scala</include>
</includes>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>child-project/src/main/resources/reference.conf</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-testkit_2.11 -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_${scalaMajorVersion}</artifactId>
<version>${akkaVersion}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scalactic/scalactic_2.11 -->
<dependency>
<groupId>org.scalactic</groupId>
<artifactId>scalactic_${scalaMajorVersion}</artifactId>
<version>${scalacticVersion}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scalatest/scalatest_2.11 -->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scalaMajorVersion}</artifactId>
<version>${scalatestVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.1.1</version>
</plugin>
</plugins>
</reporting>
</project>
子模块中的pom.xml
:
<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>
<parent>
<groupId>parent-project</groupId>
<artifactId>my.package.name</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>
<artifactId>child-project</artifactId>
<name>Child Project</name>
<url>http://maven.apache.org</url>
</project>
那么如何才能看到resources.conf