多模块maven项目通过管道部署到Heroku

时间:2018-09-19 23:05:02

标签: maven spring-boot heroku heroku-postgres heroku-cli

我无法使用Bitbucket管道部署项目。接下来是我的项目体系结构:我有一个带有两个模块的 parent pom:第一个是 engine ,它像一个普通的Java库,作为依赖项包含在第二个模块中,服务,它是Spring Boot应用程序。 父级的的pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>

<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<name>Parent</name>

<dependencies>
    <dependency>
        <groupId>com.heroku.sdk</groupId>
        <artifactId>heroku-maven-plugin</artifactId>
        <version>2.0.6</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.heroku.sdk</groupId>
            <artifactId>heroku-maven-plugin</artifactId>
            <version>2.0.6</version>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <spring.profiles.active>dev</spring.profiles.active>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <spring.profiles.active>prod</spring.profiles.active>
        </properties>
    </profile>
</profiles>

<modules>
    <module>engine</module>
    <module>service</module>
</modules>

引擎

<parent>
    <groupId>com.parent</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
</parent>

<groupId>com.engine</groupId>
<artifactId>engine</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Engine</name>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
    </plugins>
</build>

服务

<parent>
    <groupId>com.parent</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
</parent>

<artifactId>service</artifactId>
<packaging>jar</packaging>

<name>Service</name>

<dependencies>
    <dependency>
        <groupId>com.engine</groupId>
        <artifactId>engine</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
    </dependency>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Bitbucket管道

image: maven:3.3.9
clone:
depth: full
pipelines:
  default:
    - step:
        script:
          - git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD
          - mvn clean package
          - kill -9 $(lsof -t -i:$PORT -sTCP:LISTEN)
          - java -jar $JAVA_OPTS -Dspring.profiles.active=prod -Dserver.port=$PORT service/target/service-1.0.jar

Procfile

web: java -jar $JAVA_OPTS -Dspring.profiles.active=prod -Dserver.port=$PORT service/target/service-1.0.jar

是的,-Dspring.profiles.active=prod表示我具有 application-prod.properties ,该文件位于服务模块中,并且该文件中的配置确实可以正常工作,因为当我在本地运行时:

mvn clean heroku:deploy

它已成功部署在heroku上,并且我的应用程序在blabla.heroku.com上运行良好,但是有一件事:当我进行heroku run bash并对其进行探索时,我发现有一个 pom.xml 是我的 service 的根目录,而不是 parent ,并且还有一个 target 文件夹,其中 service-1.0。 jar 存在。就像我没有多模块项目,只有服务项目一样。当我确实推送到管道开始工作的heroku主节点或原始主节点时,构建失败,因为它看不到我的属性文件,并且无法获取数据库连接配置。当我现在heroku run bash时,我在根文件夹和两个文件夹中看到 parent pom.xml engine service ,但是由于构建失败,它们没有jar文件。如何使heroku查看 service 模块中的 application-prod.properties 文件?为什么它与mvn clean heroku:deploy管道如此不同?请帮助我

0 个答案:

没有答案