WASHINGTON — U.S. construction spending staged a strong rebound in July, rising by the largest amount in more than two years. All major categories of construction showed gains in an encouraging sign that spending on building projects will help boost the economy in the second half of this year.

Construction spending rose 1.8 percent in July, the biggest one-month gain since May 2012, the Commerce Department reported Tuesday. It followed a 0.9 percent decline in June, the largest setback in a year. That decline had been blamed in part on soggy weather which depressed construction activity in many parts of the country.

The July rebound pushed total construction to a seasonally adjusted annual rate of $981.3 billion, the highest level since December 2008. Spending on housing, non-residential and government projects all increased.

Construction spend is now 8.2 percent higher than it was a year ago as it continues to advance following a deep plunge during the Great Recession when builders sharply cut back because of a glut of unsold homes.

Housing construction was up 0.7 percent in July to an annual rate of $358.1 billion after two months of declines. Spending on single-family homes rose 0.5 percent and is 9.4 percent higher than a year ago while apartment construction rose 0.2 percent and is 41 percent higher than a year ago.

Spending on non-residential projects increased 2.1 percent to an annual rate of $343.6 billion with the strength led by gains in hotel construction, electric power transmission and manufacturing.

Spending on government projects rose 3 percent, the largest gain since October. Spending on state and local projects was up 3.4 percent, offsetting a 1.1 percent drop in federal construction spending.

A slump in construction in the winter contributed to the economy, as measured by the gross domestic product, shrinking at an annual rate of 2.1 percent in the January-March quarter. That was the biggest plunge in GDP since the first quarter of 2009 during the depths of the Great Recession.

But the economy rebounded sharply in the April-June quarter, growing at an annual rate of 4.2 percent. Economists think economic growth will continue at a solid pace in the second half of this year although an initial forecast of 3 percent growth in the July-September quarter may be trimmed following a report Friday that consumer spending fell in July. Economists remain optimistic that Americans will resume shopping in coming months, helped by rising employment and stronger consumer confidence.

In the spring, residential construction grew at a 7.2 percent rate after two quarterly declines and spending by businesses on construction projects rose at an annual rate of 9.4 percent.