同一仓库含Spring Boot与Angular 5,Travis CI是否支持?
Absolutely! This is totally feasible—Travis CI lets you run multiple build workflows in a single .travis.yml file, so you can handle both your Java-based Spring Boot backend and Angular 5 frontend without splitting your repo or setting up separate CI pipelines. Here's a step-by-step breakdown of how to make this work:
1. Set up the right environments
Travis supports specifying multiple languages in your config, which is perfect here since we need Java for Spring Boot and Node.js for Angular 5. Add these lines to your config:
language: java node_js: 10 # Angular 5 plays nicely with Node.js 10 (LTS versions are most reliable) jdk: openjdk8 # Adjust this if your Spring Boot project uses a newer Java version
2. Install dependencies for the Angular frontend
Before building the Angular app, you'll need to install the correct version of Angular CLI (Angular 5 works best with @angular/cli@1.7.x). Add these pre-build steps:
before_script: # Install Angular CLI compatible with Angular 5 - npm install -g @angular/cli@1.7.4 # Move into your Angular project directory (update the path to match your repo structure) - cd ./frontend - npm install # Jump back to the root directory for the Spring Boot build - cd ../
3. Run build commands for both projects
Add script steps to compile both the frontend and backend. Adjust the paths and build commands to match your project setup:
script: # Build the Angular 5 project in production mode - cd ./frontend - ng build --prod - cd ../ # Build the Spring Boot project with Maven (replace with ./gradlew build if you use Gradle) - mvn clean package -DskipTests
4. Optional: Run tests for both projects
If you want Travis to execute your test suites for both apps, expand the script section like this:
script: # Run Angular unit tests and end-to-end tests - cd ./frontend - ng test --watch=false - ng e2e --protractor-config=e2e/protractor-ci.conf.js - cd ../ # Run Spring Boot tests and build the package - mvn clean test package
Quick tips to avoid issues:
- Double-check your directory paths—if your Angular app is in a folder named
clientinstead offrontend, update thosecdcommands accordingly. - Stick to Node.js versions that are compatible with Angular 5 (Node.js 8 or 10 are safe bets; newer versions might cause compatibility issues).
- If you're using Gradle for your Spring Boot project, swap out the Maven commands with the appropriate Gradle tasks (like
./gradlew clean build).
With this setup, every time you push changes to your GitHub repo, Travis will run both builds (and tests if you included them), ensuring both parts of your application are validated.
内容的提问来源于stack exchange,提问作者Carlos Vázquez Losada

