0

I have two truffle projects on my local machine. When running truffle test on one project, the output indicates that all contracts from both projects are being compiled. I'd like to only compile the contracts contained in the current project directory.

Things I have done already:

  • Place each project in a virtual environment
  • Delete the current ganache workspace and start a fresh one
  • Run truffle migrate --reset

The issue appears to be coming from the lines below as all contracts on the machine get listed after this output.

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1

1 Answer 1

0

in general, truffle compiles all the contracts inside contracts folder within the current directory (the directory your terminal is showing).
running the truffle compile command in your truffle project directory will only compile the contracts in the current contracts folder, depending on the compiler version in truffle-config.js in the same directory.

compilers: {
    solc: {
       version: "0.4.24",    // Fetch exact version from solc-bin (default: truffle's version)
       docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
       settings: {          // See the solidity docs for advice about optimization and evmVersion
        optimizer: {
          enabled: false,
          runs: 200
        },
        evmVersion: "byzantium"
       }
    }
  }

and when you want to use the truffle migrate command, you can give it a specific blockchain to connect to, like truffle migrate --network myNetwork:

networks: {
    myNetwork: { // default with truffle unbox is 7545, but we can use develop to test changes, ex. truffle migrate --network develop
      host: "127.0.0.1",
      port: 8545,
      network_id: "*"
    }
  }

so you can configure each truffle-config.js file for different projects with different compilers and blockchains. like this, you can have different virtual blockchains like ganache and truffle develop etc, and configure the truffle-config.js of each of your projects to connect the one of them. this way you can have completely separate projects running at the same time, let alone the different truffle compilers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.